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);
}
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);
}
}
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));
}
}
Aggregations