diff options
author | Michal Minar <miminar@redhat.com> | 2014-06-24 12:11:08 +0200 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2014-06-25 15:17:17 +0200 |
commit | 1837cd02c4eda76a0fb05f88a2c3e1fb557738c0 (patch) | |
tree | 9ccca763b1af9d786441bfad251835d55daadfa5 /src | |
parent | bb9b0a15cb4c4de8ed59b0da13b6503b3a2508f4 (diff) | |
download | openlmi-providers-1837cd02c4eda76a0fb05f88a2c3e1fb557738c0.tar.gz openlmi-providers-1837cd02c4eda76a0fb05f88a2c3e1fb557738c0.tar.xz openlmi-providers-1837cd02c4eda76a0fb05f88a2c3e1fb557738c0.zip |
software-dbus: implemented LMI_SoftwareInstallationJob
Diffstat (limited to 'src')
-rw-r--r-- | src/software-dbus/LMI_SoftwareInstallationJobProvider.c | 241 |
1 files changed, 227 insertions, 14 deletions
diff --git a/src/software-dbus/LMI_SoftwareInstallationJobProvider.c b/src/software-dbus/LMI_SoftwareInstallationJobProvider.c index 92fda7d..47f4c82 100644 --- a/src/software-dbus/LMI_SoftwareInstallationJobProvider.c +++ b/src/software-dbus/LMI_SoftwareInstallationJobProvider.c @@ -1,10 +1,41 @@ +/* + * Copyright (C) 2012-2014 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Michal Minar <miminar@redhat.com> + */ + #include <konkret/konkret.h> #include "LMI_SoftwareInstallationJob.h" +#include "CIM_Error.h" +#include "openlmi.h" +#include "sw-utils.h" +#include "job_manager.h" +#include "lmi_sw_job.h" + +#define KILL_JOB_SUCCESS 0 +#define GET_ERROR_SUCCESS 0 +#define REQUESTED_STATE_TERMINATE 4 +#define REQUEST_STATE_CHANGE_COMPLETED_WITH_NO_ERROR 0 static const CMPIBroker* _cb = NULL; -static void LMI_SoftwareInstallationJobInitialize() +static void LMI_SoftwareInstallationJobInitialize(const CMPIContext *ctx) { + software_init(provider_name, _cb, ctx, provider_config_defaults); } static CMPIStatus LMI_SoftwareInstallationJobCleanup( @@ -12,7 +43,7 @@ static CMPIStatus LMI_SoftwareInstallationJobCleanup( const CMPIContext* cc, CMPIBoolean term) { - CMReturn(CMPI_RC_OK); + return software_cleanup(); } static CMPIStatus LMI_SoftwareInstallationJobEnumInstanceNames( @@ -32,7 +63,49 @@ static CMPIStatus LMI_SoftwareInstallationJobEnumInstances( const CMPIObjectPath* cop, const char** properties) { - CMReturn(CMPI_RC_OK); + CMPIStatus status = {CMPI_RC_OK, NULL}; + gchar *jobid; + LmiJob *job; + CMPIInstance *inst; + guint *jobnum; + guint *jobnums = jobmgr_get_job_numbers(NULL); + + if (jobnums == NULL) + CMReturn(CMPI_RC_ERR_FAILED); + jobnum = jobnums; + + while (*jobnum) { + job = jobmgr_get_job_by_number(*jobnum); + if (!job) + // job may have been deleted since numbers query + continue; + + if (!LMI_IS_SW_INSTALLATION_JOB(job)) { + g_object_unref(job); + continue; + } + + + status = jobmgr_job_to_cim_instance(job, &inst); + g_object_unref(job); + if (status.rc) { + if (status.msg) { + jobid = lmi_job_get_jobid(job); + lmi_warn("Failed to make cim instance out of job \"%s\": %s", + jobid, status.msg); + g_free(jobid); + continue; + } + } + + CMReturnInstance(cr, inst); + ++jobnum; + } + + g_free(jobnums); + + KSetStatus(&status, OK); + return status; } static CMPIStatus LMI_SoftwareInstallationJobGetInstance( @@ -42,8 +115,27 @@ static CMPIStatus LMI_SoftwareInstallationJobGetInstance( const CMPIObjectPath* cop, const char** properties) { - return KDefaultGetInstance( - _cb, mi, cc, cr, cop, properties); + LmiJob *job; + CMPIStatus status = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + gchar *jobid = NULL; + + if ((status = jobmgr_get_job_matching_op(cop, &job)).rc) + return status; + + status = jobmgr_job_to_cim_instance(job, &inst); + g_object_unref(job); + if (status.rc) { + if (status.msg) { + jobid = lmi_job_get_jobid(job); + lmi_warn("Failed to make cim instance out of job \"%s\": %s", + jobid, status.msg); + g_free(jobid); + return status; + } + } + CMReturnInstance(cr, inst); + return status; } static CMPIStatus LMI_SoftwareInstallationJobCreateInstance( @@ -64,7 +156,29 @@ static CMPIStatus LMI_SoftwareInstallationJobModifyInstance( const CMPIInstance* ci, const char** properties) { - CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); + LmiJob *job; + LMI_SoftwareInstallationJob lsij; + guint64 tbr; + CMPIStatus status = {CMPI_RC_OK, NULL}; + + if ((status = jobmgr_get_job_matching_op(cop, &job)).rc) + return status; + + LMI_SoftwareInstallationJob_InitFromInstance(&lsij, _cb, ci); + if (KHasValue(&lsij.Name)) + lmi_job_set_name(job, lsij.Name.chars); + if (KHasValue(&lsij.Priority)) + lmi_job_set_priority(job, lsij.Priority.value); + if (KHasValue(&lsij.TimeBeforeRemoval)) { + tbr = CMGetBinaryFormat(lsij.TimeBeforeRemoval.value, NULL)/1000000L; + /* treat it always as an interval */ + lmi_job_set_time_before_removal(job, tbr); + } + if (KHasValue(&lsij.DeleteOnCompletion)) + lmi_job_set_delete_on_completion(job, lsij.DeleteOnCompletion.value); + + g_object_unref(job); + return status; } static CMPIStatus LMI_SoftwareInstallationJobDeleteInstance( @@ -73,7 +187,14 @@ static CMPIStatus LMI_SoftwareInstallationJobDeleteInstance( const CMPIResult* cr, const CMPIObjectPath* cop) { - CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); + LmiJob *job; + CMPIStatus status = {CMPI_RC_OK, NULL}; + + if ((status = jobmgr_get_job_matching_op(cop, &job)).rc) + return status; + status = jobmgr_delete_job(job); + g_object_unref(job); + return status; } static CMPIStatus LMI_SoftwareInstallationJobExecQuery( @@ -91,7 +212,7 @@ CMInstanceMIStub( LMI_SoftwareInstallationJob, LMI_SoftwareInstallationJob, _cb, - LMI_SoftwareInstallationJobInitialize()) + LMI_SoftwareInstallationJobInitialize(ctx)) static CMPIStatus LMI_SoftwareInstallationJobMethodCleanup( CMPIMethodMI* mi, @@ -118,7 +239,7 @@ CMMethodMIStub( LMI_SoftwareInstallationJob, LMI_SoftwareInstallationJob, _cb, - LMI_SoftwareInstallationJobInitialize()) + LMI_SoftwareInstallationJobInitialize(ctx)) KUint32 LMI_SoftwareInstallationJob_KillJob( const CMPIBroker* cb, @@ -128,9 +249,25 @@ KUint32 LMI_SoftwareInstallationJob_KillJob( const KBoolean* DeleteOnKill, CMPIStatus* status) { + CMPIObjectPath *cop; + LmiJob *job; KUint32 result = KUINT32_INIT; - KSetStatus(status, ERR_NOT_SUPPORTED); + if ((cop = LMI_SoftwareInstallationJobRef_ToObjectPath( + self, status)) == NULL) + return result; + *status = jobmgr_get_job_matching_op(cop, &job); + CMRelease(cop); + if (status->rc) + return result; + *status = jobmgr_terminate_job(job); + if (!status->rc) { + if (KHasValue(DeleteOnKill) && DeleteOnKill->value) + *status = jobmgr_delete_job(job); + } + g_object_unref(job); + if (!status->rc) + KUint32_Set(&result, KILL_JOB_SUCCESS); return result; } @@ -143,9 +280,43 @@ KUint32 LMI_SoftwareInstallationJob_RequestStateChange( const KDateTime* TimeoutPeriod, CMPIStatus* status) { + const char *errmsg = NULL; + CMPIObjectPath *cop; + LmiJob *job; KUint32 result = KUINT32_INIT; - KSetStatus(status, ERR_NOT_SUPPORTED); + if (!KHasValue(RequestedState)) { + errmsg = "Missing RequestedState parameter."; + goto err; + } + if (RequestedState->value != REQUESTED_STATE_TERMINATE) { + errmsg = "The only supported RequestedState is TERMINATE."; + goto err; + } + if (KHasValue(TimeoutPeriod)) { + errmsg = "TimeoutPeriod parameter is not supported."; + goto err; + } + + if ((cop = LMI_SoftwareInstallationJobRef_ToObjectPath( + self, status)) == NULL) + goto err; + *status = jobmgr_get_job_matching_op(cop, &job); + CMRelease(cop); + if (status->rc) + goto err; + *status = jobmgr_terminate_job(job); + if (!status->rc) + KUint32_Set(&result, REQUEST_STATE_CHANGE_COMPLETED_WITH_NO_ERROR); + g_object_unref(job); + +err: + if (errmsg) { + lmi_error(errmsg); + KSetStatus2(cb, status, ERR_INVALID_PARAMETER, errmsg); + } + if (!status->rc) + KUint32_Set(&result, REQUEST_STATE_CHANGE_COMPLETED_WITH_NO_ERROR); return result; } @@ -157,9 +328,41 @@ KUint32 LMI_SoftwareInstallationJob_GetError( KInstance* Error, CMPIStatus* status) { + CMPIObjectPath *cop; + LmiJob *job = NULL; + CMPIInstance *inst = NULL; KUint32 result = KUINT32_INIT; - KSetStatus(status, ERR_NOT_SUPPORTED); + if ((cop = LMI_SoftwareInstallationJobRef_ToObjectPath( + self, status)) == NULL) + goto err; + *status = jobmgr_get_job_matching_op(cop, &job); + CMRelease(cop); + if (status->rc) { + KSetStatus(status, ERR_NOT_FOUND); + goto done; + } + JOB_CRITICAL_BEGIN(job); + if (lmi_job_get_state(job) == LMI_JOB_STATE_ENUM_EXCEPTION) { + if ((*status = jobmgr_job_to_cim_error(job, &inst)).rc) + goto critical_end_err; + KInstance_Set(Error, inst); + } + JOB_CRITICAL_END(job); + g_clear_object(&job); + + KUint32_Set(&result, GET_ERROR_SUCCESS); + goto done; + +critical_end_err: + JOB_CRITICAL_END(job); + g_clear_object(&job); +err: + if (!status->rc) { + lmi_error("Memory allocation failed"); + KSetStatus(status, ERR_FAILED); + } +done: return result; } @@ -172,8 +375,18 @@ KUint32 LMI_SoftwareInstallationJob_GetErrors( CMPIStatus* status) { KUint32 result = KUINT32_INIT; - - KSetStatus(status, ERR_NOT_SUPPORTED); + KInstance Error; + KInstance_Null(&Error); + LMI_SoftwareInstallationJob_GetError(cb, mi, context, self, &Error, status); + if (status->rc) + return result; + if (KHasValue(&Error)) { + KInstanceA_Init(Errors, cb, 1); + KInstanceA_Set(Errors, 0, (CMPIInstance *) Error.value); + } else { + KInstanceA_Init(Errors, cb, 0); + } + KUint32_Set(&result, GET_ERROR_SUCCESS); return result; } |