Search in sources :

Example 16 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class DeleteRemoteServerAction method execute.

@Action(name = "Delete Remote Server", description = DELETE_REMOTE_SERVER_DESC, outputs = { @Output(value = RETURN_RESULT, description = DELETE_REMOTE_SERVER_RETURN_RESULT_DESC), @Output(value = STATUS_CODE, description = STATUS_CODE_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESCRIPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_DESC), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, description = FAILURE_DESC) })
public Map<String, String> execute(@Param(value = HOST, required = true, description = HOST_DESC) String host, @Param(value = PORT, required = true, description = PORT_DESC) String port, @Param(value = PROTOCOL, required = true, description = PROTOCOL_DESC) String protocol, @Param(value = USERNAME, description = USERNAME_DESC) String username, @Param(value = PASSWORD, encrypted = true, description = PASSWORD_DESC) String password, @Param(value = PLATFORM, description = PLATFORM_DESC) String platform, @Param(value = REMOTE_NAME, required = true, description = REMOTE_NAME_DESC) String remoteName, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_DESC) String x509HostnameVerifier, @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, @Param(value = SOCKET_TIMEOUT, description = SOCKET_TIMEOUT_DESC) String socketTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONN_MAX_ROUTE_DESC) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONN_MAX_TOTAL_DESC) String connectionsMaxTotal, @Param(value = RESPONSE_CHARACTER_SET, description = RESPONSE_CHARACTER_SET_DESC) String responseCharacterSet) {
    username = defaultIfEmpty(username, EMPTY);
    password = defaultIfEmpty(password, EMPTY);
    platform = defaultIfEmpty(platform, DEFAULT_PLATFORM);
    proxyHost = defaultIfEmpty(proxyHost, EMPTY);
    proxyPort = defaultIfEmpty(proxyPort, DEFAULT_PROXY_PORT);
    proxyUsername = defaultIfEmpty(proxyUsername, EMPTY);
    proxyPassword = defaultIfEmpty(proxyPassword, EMPTY);
    trustAllRoots = defaultIfEmpty(trustAllRoots, BOOLEAN_FALSE);
    x509HostnameVerifier = defaultIfEmpty(x509HostnameVerifier, STRICT);
    keystore = defaultIfEmpty(keystore, DEFAULT_JAVA_KEYSTORE);
    keystorePassword = defaultIfEmpty(keystorePassword, CHANGEIT);
    trustKeystore = defaultIfEmpty(trustKeystore, DEFAULT_JAVA_TRUST_KEYSTORE);
    trustPassword = defaultIfEmpty(trustPassword, CHANGEIT);
    connectTimeout = defaultIfEmpty(connectTimeout, ZERO);
    socketTimeout = defaultIfEmpty(socketTimeout, ZERO);
    keepAlive = defaultIfEmpty(keepAlive, BOOLEAN_FALSE);
    connectionsMaxPerRoute = defaultIfEmpty(connectionsMaxPerRoute, CONNECTIONS_MAX_PER_ROUTE_CONST);
    connectionsMaxTotal = defaultIfEmpty(connectionsMaxTotal, CONNECTIONS_MAX_TOTAL_CONST);
    responseCharacterSet = defaultIfEmpty(responseCharacterSet, UTF8);
    final List<String> exceptionMessage = verifyCommonInputs(port, proxyPort, trustAllRoots, connectTimeout, socketTimeout, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal);
    exceptionMessage.addAll(verifyDeleteRemoteServerInputs(platform, remoteName));
    if (!exceptionMessage.isEmpty()) {
        return getFailureResultsMap(StringUtilities.join(exceptionMessage, NEW_LINE));
    }
    final DeleteRemoteServerService service = new DeleteRemoteServerService();
    Map<String, String> result;
    try {
        DeleteRemoteServerInputs inputs = new DeleteRemoteServerInputs.DeleteRemoteServerInputsBuilder().platform(platform).remoteName(remoteName).commonInputs(SiteScopeCommonInputs.builder().host(host).port(port).protocol(protocol).username(username).password(password).proxyHost(proxyHost).proxyPort(proxyPort).proxyUsername(proxyUsername).proxyPassword(proxyPassword).connectionsMaxTotal(connectionsMaxTotal).connectionsMaxPerRoute(connectionsMaxPerRoute).keepAlive(keepAlive).responseCharacterSet(responseCharacterSet).connectTimeout(connectTimeout).trustAllRoots(trustAllRoots).x509HostnameVerifier(x509HostnameVerifier).keystore(keystore).keystorePassword(keystorePassword).trustKeystore(trustKeystore).trustPassword(trustPassword).build()).build();
        result = service.execute(inputs);
        return result;
    } catch (Exception exception) {
        return getFailureResultsMap(exception);
    }
}
Also used : DeleteRemoteServerService(io.cloudslang.content.sitescope.services.DeleteRemoteServerService) DeleteRemoteServerInputs(io.cloudslang.content.sitescope.entities.DeleteRemoteServerInputs) InputsValidation.verifyDeleteRemoteServerInputs(io.cloudslang.content.sitescope.utils.InputsValidation.verifyDeleteRemoteServerInputs) Action(com.hp.oo.sdk.content.annotations.Action)

Example 17 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class DeployTemplateAction method execute.

@Action(name = "Deploy Template", description = DEPLOY_TEMPLATE_DESC, outputs = { @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), @Output(value = STATUS_CODE, description = STATUS_CODE_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESCRIPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_DESC), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, description = FAILURE_DESC) })
public Map<String, String> execute(@Param(value = HOST, description = HOST_DESC) String host, @Param(value = PORT, description = PORT_DESC) String port, @Param(value = PROTOCOL, description = PROTOCOL_DESC) String protocol, @Param(value = USERNAME, description = USERNAME_DESC) String username, @Param(value = PASSWORD, encrypted = true, description = PASSWORD_DESC) String password, @Param(value = DELIMITER, description = DELIMITER_DESC) String delimiter, @Param(value = PATH_TO_TEMPLATE, description = PATH_TO_TEMPLATE_DESC) String pathToTemplate, @Param(value = PATH_TO_TARGET_GROUP, description = PATH_TO_TARGET_GROUP_DESC) String pathToTargetGroup, @Param(value = CONNECT_TO_SERVER, description = CONNECT_TO_SERVER_DESC) String connectToServer, @Param(value = TEST_REMOTES, description = TEST_REMOTES_DESC) String testRemotes, @Param(value = CUSTOM_PARAMETERS, description = CUSTOM_PARAMETERS_DESC) String customParameters, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_DESC) String x509HostnameVerifier, @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, @Param(value = SOCKET_TIMEOUT, description = SOCKET_TIMEOUT_DESC) String socketTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONN_MAX_ROUTE_DESC) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONN_MAX_TOTAL_DESC) String connectionsMaxTotal, @Param(value = RESPONSE_CHARACTER_SET, description = RESPONSE_CHARACTER_SET_DESC) String responseCharacterSet) {
    username = defaultIfEmpty(username, EMPTY);
    password = defaultIfEmpty(password, EMPTY);
    pathToTemplate = defaultIfEmpty(pathToTemplate, EMPTY);
    pathToTargetGroup = defaultIfEmpty(pathToTargetGroup, EMPTY);
    connectToServer = defaultIfEmpty(connectToServer, BOOLEAN_TRUE);
    customParameters = defaultIfEmpty(customParameters, EMPTY);
    testRemotes = defaultIfEmpty(testRemotes, BOOLEAN_FALSE);
    delimiter = defaultIfEmpty(delimiter, DEFAULT_DELIMITER);
    proxyHost = defaultIfEmpty(proxyHost, EMPTY);
    proxyPort = defaultIfEmpty(proxyPort, DEFAULT_PROXY_PORT);
    proxyUsername = defaultIfEmpty(proxyUsername, EMPTY);
    proxyPassword = defaultIfEmpty(proxyPassword, EMPTY);
    trustAllRoots = defaultIfEmpty(trustAllRoots, BOOLEAN_FALSE);
    x509HostnameVerifier = defaultIfEmpty(x509HostnameVerifier, STRICT);
    keystore = defaultIfEmpty(keystore, DEFAULT_JAVA_KEYSTORE);
    keystorePassword = defaultIfEmpty(keystorePassword, CHANGEIT);
    trustKeystore = defaultIfEmpty(trustKeystore, DEFAULT_JAVA_TRUST_KEYSTORE);
    trustPassword = defaultIfEmpty(trustPassword, CHANGEIT);
    connectTimeout = defaultIfEmpty(connectTimeout, ZERO);
    socketTimeout = defaultIfEmpty(socketTimeout, ZERO);
    keepAlive = defaultIfEmpty(keepAlive, BOOLEAN_FALSE);
    connectionsMaxPerRoute = defaultIfEmpty(connectionsMaxPerRoute, CONNECTIONS_MAX_PER_ROUTE_CONST);
    connectionsMaxTotal = defaultIfEmpty(connectionsMaxTotal, CONNECTIONS_MAX_TOTAL_CONST);
    responseCharacterSet = defaultIfEmpty(responseCharacterSet, UTF8);
    final List<String> exceptionMessage = verifyCommonInputs(port, proxyPort, trustAllRoots, connectTimeout, socketTimeout, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal);
    exceptionMessage.addAll(verifyDeployTemplateInputs(pathToTemplate, pathToTargetGroup, connectToServer, testRemotes));
    if (!exceptionMessage.isEmpty()) {
        return getFailureResultsMap(StringUtilities.join(exceptionMessage, NEW_LINE));
    }
    final DeployTemplateService service = new DeployTemplateService();
    Map<String, String> result;
    try {
        DeployTemplateInputs inputs = new DeployTemplateInputs.DeployTemplateInputsBuilder().pathToTemplate(pathToTemplate).pathToTargetGroup(pathToTargetGroup).delimiter(delimiter).connectToServer(connectToServer).testRemotes(testRemotes).customParameters(customParameters).commonInputs(SiteScopeCommonInputs.builder().host(host).port(port).protocol(protocol).username(username).password(password).proxyHost(proxyHost).proxyPort(proxyPort).proxyUsername(proxyUsername).proxyPassword(proxyPassword).connectionsMaxTotal(connectionsMaxTotal).connectionsMaxPerRoute(connectionsMaxPerRoute).keepAlive(keepAlive).responseCharacterSet(responseCharacterSet).connectTimeout(connectTimeout).trustAllRoots(trustAllRoots).x509HostnameVerifier(x509HostnameVerifier).keystore(keystore).keystorePassword(keystorePassword).trustKeystore(trustKeystore).trustPassword(trustPassword).build()).build();
        result = service.execute(inputs);
        return result;
    } catch (Exception ex) {
        return getFailureResultsMap(ex);
    }
}
Also used : InputsValidation.verifyDeployTemplateInputs(io.cloudslang.content.sitescope.utils.InputsValidation.verifyDeployTemplateInputs) DeployTemplateInputs(io.cloudslang.content.sitescope.entities.DeployTemplateInputs) DeployTemplateService(io.cloudslang.content.sitescope.services.DeployTemplateService) DeployTemplateAction(io.cloudslang.content.sitescope.constants.Descriptions.DeployTemplateAction) Action(com.hp.oo.sdk.content.annotations.Action)

Example 18 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class ChangeMonitorGroupStatusAction method execute.

@Action(name = "Change Monitor Group Status", description = CHANGE_MONITOR_GROUP_STATUS_DESC, outputs = { @Output(value = RETURN_RESULT, description = CHANGE_MONITOR_GROUP_STATUS_RETURN_RESULT_DESC), @Output(value = STATUS_CODE, description = STATUS_CODE_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESCRIPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_DESC), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, description = FAILURE_DESC) })
public Map<String, String> execute(@Param(value = HOST, required = true, description = HOST_DESC) String host, @Param(value = PORT, required = true, description = PORT_DESC) String port, @Param(value = PROTOCOL, required = true, description = PROTOCOL_DESC) String protocol, @Param(value = USERNAME, description = USERNAME_DESC) String username, @Param(value = PASSWORD, encrypted = true, description = PASSWORD_DESC) String password, @Param(value = FULL_PATH_TO_GROUP, required = true, description = FULL_PATH_TO_GROUP_DESC) String fullPathToGroup, @Param(value = DELIMITER, description = DELIMITER_DESC) String delimiter, @Param(value = STATUS, description = STATUS_DESC) String status, @Param(value = TIME_PERIOD, description = TIME_PERIOD_DESC) String timePeriod, @Param(value = FROM_TIME, description = FROM_TIME_DESC) String fromTime, @Param(value = TO_TIME, description = TO_TIME_DESC) String toTime, @Param(value = DESCRIPTION, description = DESCRIPTION_DESC) String description, @Param(value = IDENTIFIER, description = IDENTIFIER_ENABLE_DESC) String identifier, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_DESC) String x509HostnameVerifier, @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, @Param(value = SOCKET_TIMEOUT, description = SOCKET_TIMEOUT_DESC) String socketTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONN_MAX_ROUTE_DESC) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONN_MAX_TOTAL_DESC) String connectionsMaxTotal, @Param(value = RESPONSE_CHARACTER_SET, description = RESPONSE_CHARACTER_SET_DESC) String responseCharacterSet) {
    username = defaultIfEmpty(username, EMPTY);
    password = defaultIfEmpty(password, EMPTY);
    delimiter = defaultIfEmpty(delimiter, DEFAULT_DELIMITER);
    identifier = defaultIfEmpty(identifier, EMPTY);
    status = defaultIfEmpty(status, DISABLED);
    timePeriod = defaultIfEmpty(timePeriod, EMPTY);
    fromTime = defaultIfEmpty(fromTime, EMPTY);
    toTime = defaultIfEmpty(toTime, EMPTY);
    description = defaultIfEmpty(description, EMPTY);
    proxyHost = defaultIfEmpty(proxyHost, EMPTY);
    proxyPort = defaultIfEmpty(proxyPort, DEFAULT_PROXY_PORT);
    proxyUsername = defaultIfEmpty(proxyUsername, EMPTY);
    proxyPassword = defaultIfEmpty(proxyPassword, EMPTY);
    trustAllRoots = defaultIfEmpty(trustAllRoots, BOOLEAN_FALSE);
    x509HostnameVerifier = defaultIfEmpty(x509HostnameVerifier, STRICT);
    keystore = defaultIfEmpty(keystore, DEFAULT_JAVA_KEYSTORE);
    keystorePassword = defaultIfEmpty(keystorePassword, CHANGEIT);
    trustKeystore = defaultIfEmpty(trustKeystore, DEFAULT_JAVA_TRUST_KEYSTORE);
    trustPassword = defaultIfEmpty(trustPassword, CHANGEIT);
    connectTimeout = defaultIfEmpty(connectTimeout, ZERO);
    socketTimeout = defaultIfEmpty(socketTimeout, ZERO);
    keepAlive = defaultIfEmpty(keepAlive, BOOLEAN_FALSE);
    connectionsMaxPerRoute = defaultIfEmpty(connectionsMaxPerRoute, CONNECTIONS_MAX_PER_ROUTE_CONST);
    connectionsMaxTotal = defaultIfEmpty(connectionsMaxTotal, CONNECTIONS_MAX_TOTAL_CONST);
    responseCharacterSet = defaultIfEmpty(responseCharacterSet, UTF8);
    final ChangeMonitorGroupStatusService service = new ChangeMonitorGroupStatusService();
    Map<String, String> result;
    final List<String> exceptionMessage = verifyCommonInputs(port, proxyPort, trustAllRoots, connectTimeout, socketTimeout, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal);
    exceptionMessage.addAll(verifyChangeMonitorGroupStatusInputs(fullPathToGroup, status));
    if (!exceptionMessage.isEmpty()) {
        return getFailureResultsMap(StringUtilities.join(exceptionMessage, NEW_LINE));
    }
    try {
        ChangeMonitorGroupStatusInputs inputs = new ChangeMonitorGroupStatusInputs.ChangeMonitorGroupStatusInputsBuilder().fullPathToGroup(fullPathToGroup).delimiter(delimiter).identifier(identifier).status(status).timePeriod(timePeriod).fromTime(fromTime).toTime(toTime).description(description).commonInputs(SiteScopeCommonInputs.builder().host(host).port(port).protocol(protocol).username(username).password(password).proxyHost(proxyHost).proxyPort(proxyPort).proxyUsername(proxyUsername).proxyPassword(proxyPassword).connectionsMaxTotal(connectionsMaxTotal).connectionsMaxPerRoute(connectionsMaxPerRoute).keepAlive(keepAlive).responseCharacterSet(responseCharacterSet).connectTimeout(connectTimeout).trustAllRoots(trustAllRoots).x509HostnameVerifier(x509HostnameVerifier).keystore(keystore).keystorePassword(keystorePassword).trustKeystore(trustKeystore).trustPassword(trustPassword).build()).build();
        result = service.execute(inputs);
        return result;
    } catch (Exception exception) {
        return getFailureResultsMap(exception);
    }
}
Also used : ChangeMonitorGroupStatusInputs(io.cloudslang.content.sitescope.constants.Inputs.ChangeMonitorGroupStatusInputs) InputsValidation.verifyChangeMonitorGroupStatusInputs(io.cloudslang.content.sitescope.utils.InputsValidation.verifyChangeMonitorGroupStatusInputs) ChangeMonitorGroupStatusInputs(io.cloudslang.content.sitescope.entities.ChangeMonitorGroupStatusInputs) ChangeMonitorGroupStatusService(io.cloudslang.content.sitescope.services.ChangeMonitorGroupStatusService) ChangeMonitorGroupStatusAction(io.cloudslang.content.sitescope.constants.Descriptions.ChangeMonitorGroupStatusAction) Action(com.hp.oo.sdk.content.annotations.Action) GetGroupPropertiesAction(io.cloudslang.content.sitescope.constants.Descriptions.GetGroupPropertiesAction)

Example 19 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class ChangeMonitorStatusAction method execute.

@Action(name = "Change Monitor Status", description = CHANGE_MONITOR_STATUS_DESC, outputs = { @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), @Output(value = STATUS_CODE, description = STATUS_CODE_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESCRIPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_DESC), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, description = FAILURE_DESC) })
public Map<String, String> execute(@Param(value = HOST, required = true, description = HOST_DESC) String host, @Param(value = PORT, required = true, description = PORT_DESC) String port, @Param(value = PROTOCOL, required = true, description = PROTOCOL_DESC) String protocol, @Param(value = USERNAME, description = USERNAME_DESC) String username, @Param(value = PASSWORD, encrypted = true, description = PASSWORD_DESC) String password, @Param(value = FULL_PATH_TO_MONITOR, description = FULL_PATH_TO_MONITOR_DESC) String fullPathToMonitor, @Param(value = MONITOR_ID, description = MONITOR_ID_DESC) String monitorId, @Param(value = DELIMITER, description = DELIMITER_DESC) String delimiter, @Param(value = STATUS, description = STATUS_DESC) String status, @Param(value = TIME_PERIOD, description = TIME_PERIOD_DESC) String timePeriod, @Param(value = FROM_TIME, description = FROM_TIME_DESC) String fromTime, @Param(value = TO_TIME, description = TO_TIME_DESC) String toTime, @Param(value = DESCRIPTION, description = DESCRIPTION_DESC) String description, @Param(value = IDENTIFIER, description = IDENTIFIER_ENABLE_DESC) String identifier, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESC) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESC) String proxyPassword, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_DESC) String x509HostnameVerifier, @Param(value = KEYSTORE, description = KEYSTORE_DESC) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESC) String keystorePassword, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) String trustPassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) String connectTimeout, @Param(value = SOCKET_TIMEOUT, description = SOCKET_TIMEOUT_DESC) String socketTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONN_MAX_ROUTE_DESC) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONN_MAX_TOTAL_DESC) String connectionsMaxTotal, @Param(value = RESPONSE_CHARACTER_SET, description = RESPONSE_CHARACTER_SET_DESC) String responseCharacterSet) {
    username = defaultIfEmpty(username, EMPTY);
    password = defaultIfEmpty(password, EMPTY);
    delimiter = defaultIfEmpty(delimiter, DEFAULT_DELIMITER);
    identifier = defaultIfEmpty(identifier, EMPTY);
    status = defaultIfEmpty(status, DISABLED);
    timePeriod = defaultIfEmpty(timePeriod, EMPTY);
    fromTime = defaultIfEmpty(fromTime, EMPTY);
    toTime = defaultIfEmpty(toTime, EMPTY);
    description = defaultIfEmpty(description, EMPTY);
    proxyHost = defaultIfEmpty(proxyHost, EMPTY);
    proxyPort = defaultIfEmpty(proxyPort, DEFAULT_PROXY_PORT);
    proxyUsername = defaultIfEmpty(proxyUsername, EMPTY);
    proxyPassword = defaultIfEmpty(proxyPassword, EMPTY);
    trustAllRoots = defaultIfEmpty(trustAllRoots, BOOLEAN_FALSE);
    x509HostnameVerifier = defaultIfEmpty(x509HostnameVerifier, STRICT);
    keystore = defaultIfEmpty(keystore, DEFAULT_JAVA_KEYSTORE);
    keystorePassword = defaultIfEmpty(keystorePassword, CHANGEIT);
    trustKeystore = defaultIfEmpty(trustKeystore, DEFAULT_JAVA_TRUST_KEYSTORE);
    trustPassword = defaultIfEmpty(trustPassword, CHANGEIT);
    connectTimeout = defaultIfEmpty(connectTimeout, ZERO);
    socketTimeout = defaultIfEmpty(socketTimeout, ZERO);
    keepAlive = defaultIfEmpty(keepAlive, BOOLEAN_FALSE);
    connectionsMaxPerRoute = defaultIfEmpty(connectionsMaxPerRoute, CONNECTIONS_MAX_PER_ROUTE_CONST);
    connectionsMaxTotal = defaultIfEmpty(connectionsMaxTotal, CONNECTIONS_MAX_TOTAL_CONST);
    responseCharacterSet = defaultIfEmpty(responseCharacterSet, UTF8);
    final ChangeMonitorStatusService service = new ChangeMonitorStatusService();
    Map<String, String> result;
    final List<String> exceptionMessage = verifyCommonInputs(port, proxyPort, trustAllRoots, connectTimeout, socketTimeout, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal);
    exceptionMessage.addAll(verifyChangeMonitorStatusInputs(fullPathToMonitor, monitorId, status));
    if (!exceptionMessage.isEmpty()) {
        return getFailureResultsMap(StringUtilities.join(exceptionMessage, NEW_LINE));
    }
    try {
        ChangeMonitorStatusInputs inputs = new ChangeMonitorStatusInputs.ChangeMonitorStatusInputsBuilder().fullPathToMonitor(fullPathToMonitor).monitorId(monitorId).delimiter(delimiter).identifier(identifier).status(status).timePeriod(timePeriod).fromTime(fromTime).toTime(toTime).description(description).commonInputs(SiteScopeCommonInputs.builder().host(host).port(port).protocol(protocol).username(username).password(password).proxyHost(proxyHost).proxyPort(proxyPort).proxyUsername(proxyUsername).proxyPassword(proxyPassword).connectionsMaxTotal(connectionsMaxTotal).connectionsMaxPerRoute(connectionsMaxPerRoute).keepAlive(keepAlive).responseCharacterSet(responseCharacterSet).connectTimeout(connectTimeout).trustAllRoots(trustAllRoots).x509HostnameVerifier(x509HostnameVerifier).keystore(keystore).keystorePassword(keystorePassword).trustKeystore(trustKeystore).trustPassword(trustPassword).build()).build();
        result = service.execute(inputs);
        return result;
    } catch (Exception exception) {
        return getFailureResultsMap(exception);
    }
}
Also used : ChangeMonitorStatusService(io.cloudslang.content.sitescope.services.ChangeMonitorStatusService) InputsValidation.verifyChangeMonitorStatusInputs(io.cloudslang.content.sitescope.utils.InputsValidation.verifyChangeMonitorStatusInputs) ChangeMonitorStatusInputs(io.cloudslang.content.sitescope.entities.ChangeMonitorStatusInputs) ChangeMonitorGroupStatusAction(io.cloudslang.content.sitescope.constants.Descriptions.ChangeMonitorGroupStatusAction) Action(com.hp.oo.sdk.content.annotations.Action)

Example 20 with Action

use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.

the class GetAuthenticationToken method execute.

@Action(name = "Get Authentication Token", description = GET_AUTH_TOKEN_DESC, outputs = { @Output(value = RETURN_RESULT, description = RETURN_RESULT_DESC), @Output(value = RETURN_CODE, description = RETURN_CODE_DESC), @Output(value = EXCEPTION, description = EXCEPTION_DESC), @Output(value = AUTH_TOKEN, description = AUTH_TOKEN_OUT_DESC), @Output(value = REFRESH_TOKEN, description = REFRESH_TOKEN_OUT_DESC) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = RESOLVED, description = SUCCESS_RESPONSE_DESC), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ERROR, description = FAILURE_RESPONSE_DESC) })
public Map<String, String> execute(@Param(value = IDM_HOST, required = true, description = IDM_HOST_DESC) final String idmHostInp, @Param(value = IDM_PORT, description = IDM_PORT_DESC) final String idmPortInp, @Param(value = PROTOCOL, description = PROTOCOL_DESC) final String protocolInp, @Param(value = IDM_USERNAME, required = true, description = IDM_USERNAME_DESC) final String idmUsername, @Param(value = IDM_PASSWORD, required = true, encrypted = true, description = IDM_PASSWORD_DESC) final String idmPassword, @Param(value = DCA_USERNAME, required = true, description = DCA_USERNAME_DESC) final String dcaUsername, @Param(value = DCA_PASSWORD, required = true, encrypted = true, description = DCA_PASSWORD_DESC) final String dcaPassword, @Param(value = DCA_TENANT_NAME, description = DCA_TENANT_DESC) final String dcaTenantInp, @Param(value = PREEMPTIVE_AUTH, description = PREEMPTIVE_AUTH_DESC) final String preemptiveAuth, @Param(value = PROXY_HOST, description = PROXY_HOST_DESC) final String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESC) final String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USER_DESC) final String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASS_DESC) final String proxyPassword, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESC) final String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_DESC) final String x509HostnameVerifier, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESC) final String trustKeystoreInp, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESC) final String trustPasswordInp, @Param(value = KEYSTORE, description = KEYSTORE_DESC) final String keystoreInp, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASS_DESC) final String keystorePasswordInp, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESC) final String connectTimeout, @Param(value = SOCKET_TIMEOUT, description = SOCKET_TIMEOUT_DESC) final String socketTimeout, @Param(value = USE_COOKIES, description = USE_COOKIES_DESC) final String useCookies, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESC) final String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONN_MAX_ROUTE_DESC) final String connectionsMaxPerRoot, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONN_MAX_TOTAL_DESC) final String connectionsMaxTotal) {
    // SETUP DEFAULTS
    // default IDM port is 5443
    final String idmPortStr = defaultIfEmpty(idmPortInp, DEFAULT_IDM_PORT);
    final String protocolStr = defaultIfEmpty(protocolInp, DEFAULT_IDM_PROTOCOL);
    // todo check if tenant type needs to be validated
    final String dcaTenant = defaultIfEmpty(dcaTenantInp, DEFAULT_TENANT);
    final String trustKeystore = defaultIfEmpty(trustKeystoreInp, DEFAULT_JAVA_KEYSTORE);
    final String trustPassword = defaultIfEmpty(trustPasswordInp, DEFAULT_JAVA_KEYSTORE_PASSWORD);
    final String keystore = defaultIfEmpty(keystoreInp, DEFAULT_JAVA_KEYSTORE);
    final String keystorePassword = defaultIfEmpty(keystorePasswordInp, DEFAULT_JAVA_KEYSTORE_PASSWORD);
    // VALIDATION
    final Validator validator = new Validator().validatePort(idmPortStr, IDM_PORT).validateProtocol(protocolStr, PROTOCOL);
    if (validator.hasErrors()) {
        return getFailureResultsMap(validator.getErrors());
    }
    // SETUP HTTP INPUTS
    final HttpClientInputs httpClientInputs = new HttpClientInputs();
    httpClientInputs.setUrl(getIdmUrl(protocolInp, idmHostInp, idmPortStr));
    setIdmAuthentication(httpClientInputs, BASIC, idmUsername, idmPassword, preemptiveAuth);
    setProxy(httpClientInputs, proxyHost, proxyPort, proxyUsername, proxyPassword);
    setSecurityInputs(httpClientInputs, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword);
    setDcaCredentials(httpClientInputs, dcaUsername, dcaPassword, dcaTenant);
    setConnectionParameters(httpClientInputs, connectTimeout, socketTimeout, useCookies, keepAlive, connectionsMaxPerRoot, connectionsMaxTotal);
    httpClientInputs.setContentType(APPLICATION_JSON);
    httpClientInputs.setResponseCharacterSet(UTF_8.toString());
    httpClientInputs.setRequestCharacterSet(UTF_8.toString());
    httpClientInputs.setFollowRedirects(TRUE);
    httpClientInputs.setMethod(POST);
    try {
        final Map<String, String> httpClientResultMap = new HttpClientService().execute(httpClientInputs);
        final ObjectMapper mapper = new ObjectMapper();
        final Map responseMap = mapper.readValue(httpClientResultMap.get(RETURN_RESULT), Map.class);
        if (parseInt(httpClientResultMap.get(STATUS_CODE)) == HTTP_OK) {
            final String authToken = ((LinkedHashMap) responseMap.get("token")).get("id").toString();
            final String refreshToken = responseMap.get(REFRESH_TOKEN).toString();
            final Map<String, String> resultMap = getSuccessResultsMap(authToken);
            resultMap.put(AUTH_TOKEN, authToken);
            resultMap.put(REFRESH_TOKEN, refreshToken);
            return resultMap;
        } else {
            return getFailureResultsMap(join(responseMap.get("errors"), NEW_LINE));
        }
    } catch (Exception e) {
        return getFailureResultsMap("Failed to get authentication token.", e);
    }
}
Also used : HttpClientService(io.cloudslang.content.httpclient.services.HttpClientService) HttpClientInputs(io.cloudslang.content.httpclient.entities.HttpClientInputs) OutputUtilities.getSuccessResultsMap(io.cloudslang.content.utils.OutputUtilities.getSuccessResultsMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) OutputUtilities.getFailureResultsMap(io.cloudslang.content.utils.OutputUtilities.getFailureResultsMap) Validator(io.cloudslang.content.dca.utils.Validator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Action(com.hp.oo.sdk.content.annotations.Action)

Aggregations

Action (com.hp.oo.sdk.content.annotations.Action)230 CommonInputs (io.cloudslang.content.amazon.entities.inputs.CommonInputs)48 QueryApiExecutor (io.cloudslang.content.amazon.execute.QueryApiExecutor)47 CustomInputs (io.cloudslang.content.amazon.entities.inputs.CustomInputs)32 HttpClientInputs (io.cloudslang.content.httpclient.entities.HttpClientInputs)29 HashMap (java.util.HashMap)22 VmInputs (io.cloudslang.content.vmware.entities.VmInputs)21 HttpInputs (io.cloudslang.content.vmware.entities.http.HttpInputs)21 CommonInputs (io.cloudslang.content.couchbase.entities.inputs.CommonInputs)15 CouchbaseService (io.cloudslang.content.couchbase.execute.CouchbaseService)15 InputsUtil.getHttpClientInputs (io.cloudslang.content.couchbase.utils.InputsUtil.getHttpClientInputs)15 NetworkInputs (io.cloudslang.content.amazon.entities.inputs.NetworkInputs)11 Map (java.util.Map)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 CommonInputs (io.cloudslang.content.amazon.entities.constants.Inputs.CommonInputs)9 InstanceInputs (io.cloudslang.content.amazon.entities.inputs.InstanceInputs)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 JsonParser (com.google.gson.JsonParser)8 SFTPService (io.cloudslang.content.rft.services.SFTPService)8 ClusterComputeResourceService (io.cloudslang.content.vmware.services.ClusterComputeResourceService)8