Search in sources :

Example 1 with BaseCmd

use of com.cloud.api.BaseCmd in project cosmic by MissionCriticalCloud.

the class SpecificCmdValidationWorkerTest method testHandle.

@Test
public void testHandle() throws ResourceAllocationException {
    // Prepare
    final BaseCmd cmd = mock(BaseCmd.class);
    final Map<String, String> params = new HashMap<>();
    // Execute
    final SpecificCmdValidationWorker worker = new SpecificCmdValidationWorker();
    worker.handle(new DispatchTask(cmd, params));
    // Assert
    verify(cmd, times(1)).validateSpecificParameters(params);
}
Also used : HashMap(java.util.HashMap) BaseCmd(com.cloud.api.BaseCmd) Test(org.junit.Test)

Example 2 with BaseCmd

use of com.cloud.api.BaseCmd in project cosmic by MissionCriticalCloud.

the class CommandCreationWorker method handle.

@Override
public void handle(final DispatchTask task) {
    final BaseCmd cmd = task.getCmd();
    if (cmd instanceof BaseAsyncCreateCmd) {
        try {
            CallContext.current().setEventDisplayEnabled(cmd.isDisplay());
            ((BaseAsyncCreateCmd) cmd).create();
        } catch (final ResourceAllocationException e) {
            throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, e.getMessage(), e);
        }
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ATTEMP_TO_CREATE_NON_CREATION_CMD);
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) BaseAsyncCreateCmd(com.cloud.api.BaseAsyncCreateCmd) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) BaseCmd(com.cloud.api.BaseCmd)

Example 3 with BaseCmd

use of com.cloud.api.BaseCmd in project cosmic by MissionCriticalCloud.

the class ParamGenericValidationWorker method handle.

@Override
public void handle(final DispatchTask task) {
    final BaseCmd cmd = task.getCmd();
    final Map params = task.getParams();
    final List<String> expectedParamNames = getParamNamesForCommand(cmd);
    final StringBuilder errorMsg = new StringBuilder(ERROR_MSG_PREFIX);
    boolean foundUnknownParam = false;
    for (final Object actualParamName : params.keySet()) {
        // If none of the expected params matches, we have an unknown param
        boolean matchedCurrentParam = false;
        for (final String expectedName : expectedParamNames) {
            if (expectedName.equalsIgnoreCase((String) actualParamName)) {
                matchedCurrentParam = true;
                break;
            }
        }
        if (!matchedCurrentParam && !((String) actualParamName).equalsIgnoreCase("expires") && !((String) actualParamName).equalsIgnoreCase("signatureversion")) {
            errorMsg.append(" ").append(actualParamName);
            foundUnknownParam = true;
        }
    }
    if (foundUnknownParam) {
        s_logger.warn(String.format("Received unknown parameters for command %s. %s", cmd.getActualCommandName(), errorMsg));
    }
}
Also used : BaseCmd(com.cloud.api.BaseCmd) Map(java.util.Map)

Aggregations

BaseCmd (com.cloud.api.BaseCmd)3 BaseAsyncCreateCmd (com.cloud.api.BaseAsyncCreateCmd)1 ServerApiException (com.cloud.api.ServerApiException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1