use of alien4cloud.paas.model.OperationExecRequest in project alien4cloud by alien4cloud.
the class RuntimeStepDefinitions method iTriggerOnTheNodeTemplateTheCustomCommandOfTheInterfaceForApplicationUsingTheSecretProviderAndTheSecretCredentialsWithParameters.
/**
* Attention: Should use the json format if the property value is a function when filling the parameters.
*
* @param nodeTemplateName
* @param commandName
* @param interfaceName
* @param appName
* @param secretProviderPluginName
* @param secretCredentials
* @param operationParameters
* @throws Throwable
*/
@When("^I trigger on the node template \"([^\"]*)\" the custom command \"([^\"]*)\" of the interface \"([^\"]*)\" for application \"([^\"]*)\" using the secret provider \"([^\"]*)\" and the secret credentials \"([^\"]*)\" with parameters:$")
public void iTriggerOnTheNodeTemplateTheCustomCommandOfTheInterfaceForApplicationUsingTheSecretProviderAndTheSecretCredentialsWithParameters(String nodeTemplateName, String commandName, String interfaceName, String appName, String secretProviderPluginName, String secretCredentials, DataTable operationParameters) throws Throwable {
OperationExecRequest commandRequest = new OperationExecRequest();
commandRequest.setNodeTemplateName(nodeTemplateName);
commandRequest.setInterfaceName(interfaceName);
commandRequest.setOperationName(commandName);
commandRequest.setApplicationEnvironmentId(Context.getInstance().getDefaultApplicationEnvironmentId(appName));
if (StringUtils.isNotBlank(secretProviderPluginName) && StringUtils.isNotBlank(secretCredentials)) {
commandRequest.setSecretProviderPluginName(secretProviderPluginName);
Map<String, String> credentials = Splitter.on(",").withKeyValueSeparator(":").split(secretCredentials.replaceAll("\\s+", ""));
commandRequest.setSecretProviderCredentials(credentials);
}
if (operationParameters != null) {
Map<String, Object> parameters = Maps.newHashMap();
for (List<String> operationParameter : operationParameters.raw()) {
// check if the property is a function
if (PropertyUtils.isFunction(ToscaFunctionConstants.GET_SECRET, operationParameter.get(1))) {
parameters.put(operationParameter.get(0), PropertyUtils.toFunctionValue(operationParameter.get(1)));
} else {
parameters.put(operationParameter.get(0), operationParameter.get(1));
}
}
commandRequest.setParameters(parameters);
}
String jSon = JsonUtil.toString(commandRequest);
String restResponse = Context.getRestClientInstance().postJSon("/rest/v1/runtime/" + Context.getInstance().getApplication().getId() + "/operations/", jSon);
Context.getInstance().registerRestResponse(restResponse);
}
Aggregations