Search in sources :

Example 1 with BaseCustomIdCmd

use of org.apache.cloudstack.api.BaseCustomIdCmd in project cloudstack by apache.

the class ApiDispatcher method dispatch.

public void dispatch(final BaseCmd cmd, final Map<String, String> params, final boolean execute) throws Exception {
    // Let the chain of responsibility dispatch gradually
    standardDispatchChain.dispatch(new DispatchTask(cmd, params));
    final CallContext ctx = CallContext.current();
    ctx.setEventDisplayEnabled(cmd.isDisplay());
    if (params.get(ApiConstants.PROJECT_ID) != null) {
        Project project = _entityMgr.findByUuidIncludingRemoved(Project.class, params.get(ApiConstants.PROJECT_ID));
        ctx.setProject(project);
    }
    // TODO This if shouldn't be here. Use polymorphism and move it to validateSpecificParameters
    if (cmd instanceof BaseAsyncCmd) {
        final BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd;
        final String startEventId = params.get(ApiConstants.CTX_START_EVENT_ID);
        ctx.setStartEventId(Long.parseLong(startEventId));
        // Synchronise job on the object if needed
        if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
            Long queueSizeLimit = null;
            if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) {
                queueSizeLimit = _createSnapshotQueueSizeLimit;
            } else {
                queueSizeLimit = 1L;
            }
            if (queueSizeLimit != null) {
                if (!execute) {
                    // if we are not within async-execution context, enqueue the command
                    _asyncMgr.syncAsyncJobExecution((AsyncJob) asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
                    return;
                }
            } else {
                s_logger.trace("The queue size is unlimited, skipping the synchronizing");
            }
        }
    }
    // TODO This if shouldn't be here. Use polymorphism and move it to validateSpecificParameters
    if (cmd instanceof BaseAsyncCustomIdCmd) {
        ((BaseAsyncCustomIdCmd) cmd).checkUuid();
    } else if (cmd instanceof BaseCustomIdCmd) {
        ((BaseCustomIdCmd) cmd).checkUuid();
    }
    cmd.execute();
}
Also used : Project(com.cloud.projects.Project) BaseCustomIdCmd(org.apache.cloudstack.api.BaseCustomIdCmd) CallContext(org.apache.cloudstack.context.CallContext) DispatchTask(com.cloud.api.dispatch.DispatchTask) BaseAsyncCmd(org.apache.cloudstack.api.BaseAsyncCmd) BaseAsyncCustomIdCmd(org.apache.cloudstack.api.BaseAsyncCustomIdCmd)

Aggregations

DispatchTask (com.cloud.api.dispatch.DispatchTask)1 Project (com.cloud.projects.Project)1 BaseAsyncCmd (org.apache.cloudstack.api.BaseAsyncCmd)1 BaseAsyncCustomIdCmd (org.apache.cloudstack.api.BaseAsyncCustomIdCmd)1 BaseCustomIdCmd (org.apache.cloudstack.api.BaseCustomIdCmd)1 CallContext (org.apache.cloudstack.context.CallContext)1