use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.
the class GetDestinationClusterReference method execute.
/**
* Retrieves the destination cluster reference.
* https://developer.couchbase.com/documentation/server/3.x/admin/REST/rest-xdcr-get-ref.html
*
* Notes: To use XDCR, source and destination clusters must be established. A source cluster is the cluster where the
* original data is stored. A destination cluster is the cluster where the replica data is stored. Data is copied from
* the source cluster to the destination cluster.
*
* @param endpoint Endpoint to which request will be sent. A valid endpoint will be formatted as it shows in
* bellow example.
* Example: "http://somewhere.couchbase.com:8091"
* @param username Username used in basic authentication.
* @param password Password associated with "username" input to be used in basic authentication.
* @param proxyHost Optional - proxy server used to connect to Couchbase API. If empty no proxy will be used.
* @param proxyPort Optional - proxy server port. You must either specify values for both proxyHost and
* proxyPort inputs or leave them both empty.
* @param proxyUsername Optional - proxy server user name.
* @param proxyPassword Optional - proxy server password associated with the proxyUsername input value.
* @param trustAllRoots Optional - specifies whether to enable weak security over SSL/TSL. A certificate is
* trusted even if no trusted certification authority issued it.
* Valid values: "true", "false"
* Default value: "true"
* @param x509HostnameVerifier Optional - specifies the way the server hostname must match a domain name in the subject's
* Common Name (CN) or subjectAltName field of the X.509 certificate. Set this to "allow_all"
* to skip any checking. For the value "browser_compatible" the hostname verifier works
* the same way as Curl and Firefox. The hostname must match either the first CN, or any
* of the subject-alts. A wildcard can occur in the CN, and in any of the subject-alts.
* The only difference between "browser_compatible" and "strict" is that a wildcard (such
* as "*.foo.com") with "browser_compatible" matches all subdomains, including "a.b.foo.com".
* Valid values: "strict", "browser_compatible", "allow_all"
* Default value: "allow_all"
* @param trustKeystore Optional - pathname of the Java TrustStore file. This contains certificates from other
* parties that you expect to communicate with, or from Certificate Authorities that you
* trust to identify other parties. If the protocol (specified by the "url") is not "https"
* or if trustAllRoots is "true" this input is ignored.
* Default value: ../java/lib/security/cacerts
* Format: Java KeyStore (JKS)
* @param trustPassword Optional - password associated with the TrustStore file. If trustAllRoots is "false"
* and trustKeystore is empty, trustPassword default will be supplied.
* Default value: "changeit"
* @param keystore Optional - pathname of the Java KeyStore file. You only need this if the server requires
* client authentication. If the protocol (specified by the "url") is not "https" or if
* trustAllRoots is "true" this input is ignored.
* Format: Java KeyStore (JKS)
* Default value: ../java/lib/security/cacerts.
* @param keystorePassword Optional - password associated with the KeyStore file. If trustAllRoots is "false" and
* keystore is empty, keystorePassword default will be supplied.
* Default value: "changeit"
* @param connectTimeout Optional - time to wait for a connection to be established, in seconds. A timeout value
* of "0" represents an infinite timeout.
* Default value: "0"
* @param socketTimeout Optional - timeout for waiting for data (a maximum period inactivity between two
* consecutive data packets), in seconds. A socketTimeout value of "0" represents an
* infinite timeout.
* Default value: "0"
* @param useCookies Optional - specifies whether to enable cookie tracking or not. Cookies are stored between
* consecutive calls in a serializable session object therefore they will be available on
* a branch level. If you specify a non-boolean value, the default value is used.
* Valid values: "true", "false"
* Default value: "true"
* @param keepAlive Optional - specifies whether to create a shared connection that will be used in subsequent
* calls. If keepAlive is "false", the already open connection will be used and after
* execution it will close it.
* Valid values: "true", "false"
* Default value: "true"
* @return A map with strings as keys and strings as values that contains: outcome of the action (or failure message
* and the exception if there is one), returnCode of the operation and the ID of the request
*/
@Action(name = "Get Destination Cluster Reference", outputs = { @Output(RETURN_CODE), @Output(RETURN_RESULT), @Output(EXCEPTION) }, responses = { @Response(text = SUCCESS, field = RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = COMPARE_EQUAL, responseType = RESOLVED), @Response(text = FAILURE, field = RETURN_CODE, value = ReturnCodes.FAILURE, matchType = COMPARE_EQUAL, responseType = ERROR, isOnFail = true) })
public Map<String, String> execute(@Param(value = ENDPOINT, required = true) String endpoint, @Param(value = USERNAME, required = true) String username, @Param(value = PASSWORD, required = true, encrypted = true) String password, @Param(value = PROXY_HOST) String proxyHost, @Param(value = PROXY_PORT) String proxyPort, @Param(value = PROXY_USERNAME) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true) String proxyPassword, @Param(value = TRUST_ALL_ROOTS) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER) String x509HostnameVerifier, @Param(value = TRUST_KEYSTORE) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true) String trustPassword, @Param(value = KEYSTORE) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true) String keystorePassword, @Param(value = CONNECT_TIMEOUT) String connectTimeout, @Param(value = SOCKET_TIMEOUT) String socketTimeout, @Param(value = USE_COOKIES) String useCookies, @Param(value = KEEP_ALIVE) String keepAlive) {
try {
final HttpClientInputs httpClientInputs = getHttpClientInputs(username, password, proxyHost, proxyPort, proxyUsername, proxyPassword, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword, connectTimeout, socketTimeout, useCookies, keepAlive, METHOD_NAME);
final CommonInputs commonInputs = new CommonInputs.Builder().withAction(GET_DESTINATION_CLUSTER_REFERENCE).withApi(CLUSTER).withEndpoint(endpoint).build();
return new CouchbaseService().execute(httpClientInputs, commonInputs);
} catch (Exception exception) {
return getFailureResultsMap(exception);
}
}
use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.
the class MSSQLQuery method execute.
/**
* @param dbServerName The hostname or ip address of the database server.
* @param username The username to use when connecting to the server.
* @param password The password to use when connecting to the server.
* @param instance The name instance of MSSQL Server. Leave it blank for default instance.
* Example: MSSQLSERVER
* @param dbPort The port to connect to.
* @param databaseName The name of the database to connect to.
* @param authenticationType The type of authentication used to access the database (applicable only to MSSQL type).
* Default: sql
* Values: sql, windows
* @param dbClass The classname of the JDBC driver to use.
* @param dbURL The url required to load up the driver and make your connection.
* @param command The SQL query to execute.
* Example: "SELECT * FROM table"
* @param trustAllRoots Specifies whether to enable weak security over SSL/TSL. A certificate is trusted even if no trusted certification authority issued it.
* Default value: false
* Valid values: true, false
* Note: If trustAllRoots is set to 'false', a trustStore and a trustStorePassword must be provided.
* @param trustStore The pathname of the Java TrustStore file. This contains certificates from other parties that you expect to communicate with,
* or from Certificate Authorities that you trust to identify other parties.
* If the trustAllRoots input is set to 'true' this input is ignored.
* @param trustStorePassword The password associated with the trustStore file.
* @param delimiter The delimiter to use between resulted values in "returnResult" and column names in "columnNames".
* @param key The key to help keep multiple query results distinct.
* @param timeout Seconds to wait before timing out the SQL command execution. When the default value is used, there
* is no limit on the amount of time allowed for a running command to complete.
* Default values: 0
* @param databasePoolingProperties Properties for database pooling configuration. Pooling is disabled by default.
* Default: db.pooling.enable=false
* @param resultSetType the result set type. See JDBC folder description for more details.
* Valid values: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE,TYPE_SCROLL_SENSITIVE.
* Default value: TYPE_SCROLL_INSENSITIVE except DB2 which is overridden to TYPE_FORWARD_ONLY
* @param resultSetConcurrency the result set concurrency. See JDBC folder description for more details.
* Valid values: CONCUR_READ_ONLY, CONCUR_UPDATABLE
* Default value: CONCUR_READ_ONLY
* @param ignoreCase If set to true the inputs' letters case will be ignored and converted to lowercase.
* Valid values: true, false
* Default value: true
* @return It contains the data of one row, separated by the "delimiter".
*/
@Action(name = "MSSQL Query", outputs = { @Output(RETURN_CODE), @Output(RETURN_RESULT), @Output(EXCEPTION), @Output(ROWS_LEFT), @Output(COLUMN_NAMES), @Output(SQL_QUERY) }, responses = { @Response(text = MORE_ITEMS, field = RETURN_CODE, value = SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.NO_ACTION_TAKEN), @Response(text = NO_MORE_ITEMS, field = RETURN_CODE, value = DBReturnCodes.NO_MORE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.NO_ACTION_TAKEN), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) })
public Map<String, String> execute(@Param(value = MS_DB_SERVER_NAME, required = true) String dbServerName, @Param(value = MS_USERNAME) String username, @Param(value = MS_PASSWORD, encrypted = true) String password, @Param(value = INSTANCE) String instance, @Param(value = DB_PORT) String dbPort, @Param(value = MS_DATABASE_NAME, required = true) String databaseName, @Param(value = AUTHENTICATION_TYPE) String authenticationType, @Param(value = DB_CLASS) String dbClass, @Param(value = DB_URL) String dbURL, @Param(value = MS_COMMAND, required = true) String command, @Param(value = TRUST_ALL_ROOTS) String trustAllRoots, @Param(value = TRUST_STORE) String trustStore, @Param(value = TRUST_STORE_PASSWORD) String trustStorePassword, @Param(value = MS_DELIMITER, required = true) String delimiter, @Param(value = MS_KEY, required = true) String key, @Param(value = TIMEOUT) String timeout, @Param(value = DATABASE_POOLING_PROPERTIES) String databasePoolingProperties, @Param(value = RESULT_SET_TYPE) String resultSetType, @Param(value = RESULT_SET_CONCURRENCY) String resultSetConcurrency, @Param(value = IGNORE_CASE) String ignoreCase, @Param(value = GLOBAL_SESSION_OBJECT) GlobalSessionObject<Map<String, Object>> globalSessionObject) {
String dbType = MSSQL_DB_TYPE;
String authLibraryPath = EMPTY;
username = defaultIfEmpty(username, EMPTY);
password = defaultIfEmpty(password, EMPTY);
instance = defaultIfEmpty(instance, EMPTY);
authenticationType = defaultIfEmpty(authenticationType, AUTH_SQL);
trustAllRoots = defaultIfEmpty(trustAllRoots, FALSE);
trustStore = defaultIfEmpty(trustStore, EMPTY);
trustStorePassword = defaultIfEmpty(trustStorePassword, EMPTY);
timeout = defaultIfEmpty(timeout, DEFAULT_TIMEOUT);
resultSetType = defaultIfEmpty(resultSetType, TYPE_SCROLL_INSENSITIVE);
resultSetConcurrency = defaultIfEmpty(resultSetConcurrency, CONCUR_READ_ONLY);
ignoreCase = defaultIfEmpty(ignoreCase, TRUE);
dbClass = getOrDefaultDBClassMSSQLQuery(dbClass, dbType, authenticationType);
String windowsDomain = null;
if (AUTH_WINDOWS.equalsIgnoreCase(authenticationType) && username.contains("\\")) {
windowsDomain = username.substring(0, username.indexOf("\\"));
username = username.substring(username.indexOf("\\") + 1);
}
final List<String> preInputsValidation = validateMSSqlQueryInputs(dbServerName, dbType, username, password, instance, dbPort, databaseName, authenticationType, command, trustAllRoots, trustStore, trustStorePassword, timeout, resultSetType, resultSetConcurrency, ignoreCase);
if (!preInputsValidation.isEmpty()) {
return getFailureResultsMap(StringUtils.join(preInputsValidation, NEW_LINE));
}
final boolean ignoreCaseBool = toBoolean(ignoreCase);
dbType = getDbType(dbType);
final SQLInputs sqlInputs = SQLInputs.builder().dbServer(dbServerName).dbType(dbType).username(username).password(password).instance(getOrLower(instance, ignoreCaseBool)).dbPort(getOrDefaultDBPort(dbPort, dbType)).dbName(getOrLower(defaultIfEmpty(databaseName, EMPTY), ignoreCaseBool)).authenticationType(authenticationType).dbClass(dbClass).dbUrl(defaultIfEmpty(dbURL, EMPTY)).sqlCommand(command).trustAllRoots(toBoolean(trustAllRoots)).trustStore(trustStore).trustStorePassword(trustStorePassword).authLibraryPath(authLibraryPath).strDelim(delimiter).key(key).timeout(toInteger(timeout)).databasePoolingProperties(getOrDefaultDBPoolingProperties(databasePoolingProperties, EMPTY)).resultSetType(getResultSetTypeForDbType(resultSetType, dbType)).resultSetConcurrency(getResultSetConcurrency(resultSetConcurrency)).ignoreCase(ignoreCaseBool).isNetcool(checkIsNetcool(dbType)).windowsDomain(windowsDomain).build();
try {
final String aKey = getSqlKey(sqlInputs);
final String strKeyCol = format(KEY_COLUMNS, aKey);
globalSessionObject = getOrDefaultGlobalSessionObj(globalSessionObject);
final Map<String, Object> globalMap = globalSessionObject.get();
if (globalMap.containsKey(aKey)) {
sqlInputs.setLRows(getRowsFromGlobalSessionMap(globalSessionObject, aKey));
sqlInputs.setStrColumns(getStrColumns(globalSessionObject, strKeyCol));
} else {
if (AUTH_WINDOWS.equalsIgnoreCase(authenticationType)) {
try {
sqlInputs.setAuthLibraryPath(exportPathToAuthDll());
} catch (Exception e) {
return getFailureResultsMap(e);
}
}
SQLQueryService.executeSqlQuery(sqlInputs);
}
Map<String, String> result = new HashMap<>();
if (!sqlInputs.getLRows().isEmpty()) {
final String getFirstRow = sqlInputs.getLRows().remove(0);
result = getSuccessResultsMap(getFirstRow);
result.put(COLUMN_NAMES, sqlInputs.getStrColumns());
result.put(ROWS_LEFT, String.valueOf(sqlInputs.getLRows().size()));
globalMap.put(aKey, sqlInputs.getLRows());
globalMap.put(strKeyCol, sqlInputs.getStrColumns());
globalSessionObject.setResource(new SQLSessionResource(globalMap));
} else {
result.put(SQL_QUERY, sqlInputs.getSqlCommand());
result.put(RETURN_RESULT, NO_MORE);
result.put(ROWS_LEFT, ZERO);
result.put(RETURN_CODE, DBReturnCodes.NO_MORE);
globalMap.put(aKey, null);
}
return result;
} catch (Exception e) {
final Map<String, String> failureMap = getFailureResultsMap(e);
failureMap.put(ROWS_LEFT, ZERO);
return failureMap;
}
}
use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.
the class SQLCommand method execute.
/**
* @param dbServerName The hostname or ip address of the database server.
* @param dbType The type of database to connect to.
* Valid values: Oracle, MSSQL, Sybase, Netcool, DB2, PostgreSQL and Custom.
* @param username The username to use when connecting to the database.
* @param password The password to use when connecting to the database.
* @param instance The name instance (for MSSQL Server). Leave it blank for default instance.
* @param dbPort The port to connect to.
* Default values: Oracle: 1521, MSSQL: 1433, Sybase: 5000, Netcool: 4100, DB2: 50000, PostgreSQL: 5432.
* @param databaseName The name of the database.
* @param authenticationType The type of authentication used to access the database (applicable only to MSSQL type).
* Default: sql
* Values: sql, windows
* @param dbClass The classname of the JDBC driver to use.
* Examples: "oracle.jdbc.driver.OracleDriver", "org.postgresql.Driver"
* @param dbURL The url required to load up the driver and make your connection.
* Examples: "jdbc:oracle:drivertype:@database", "jdbc:postgresql://host:port/database"
* @param command The command to execute.
* Example: "INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...)"
* @param trustAllRoots Specifies whether to enable weak security over SSL/TSL. A certificate is trusted even if no trusted certification authority issued it.
* Default value: false
* Valid values: true, false
* Note: If trustAllRoots is set to 'false', a trustStore and a trustStorePassword must be provided.
* @param trustStore The pathname of the Java TrustStore file. This contains certificates from other parties that you expect to communicate with,
* or from Certificate Authorities that you trust to identify other parties.
* If the trustAllRoots input is set to 'true' this input is ignored.
* @param trustStorePassword The password associated with the trustStore file.
* @param authLibraryPath The path to the folder where sqljdbc_auth.dll is located. This path must be provided when using windows authentication.
* Note: The sqljdbc_auth.dll can be found inside the sqljdbc driver. The driver can be downloaded from https://www.microsoft.com/en-us/download/details.aspx?id=11774.
* The downloaded jar should be extracted and the library can be found in the 'auth' folder.
* The path provided should be the path to the folder where the sqljdbc_auth.dll library is located, not the path to the file itself.
* @param databasePoolingProperties Properties for database pooling configuration. Pooling is disabled by default.
* Default: db.pooling.enable=false
* Example: db.pooling.enable=true
* @param resultSetType The result set type. See JDBC folder description for more details.
* Valid values: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE,TYPE_SCROLL_SENSITIVE.
* Default value: TYPE_FORWARD_ONLY
* @param resultSetConcurrency The result set concurrency. See JDBC folder description for more details.
* Valid values: CONCUR_READ_ONLY, CONCUR_UPDATABLE
* Default value: CONCUR_READ_ONLY
* @return The return result of SQL command.
*/
@Action(name = "SQL Command", outputs = { @Output(RETURN_CODE), @Output(RETURN_RESULT), @Output(UPDATE_COUNT), @Output(OUTPUT_TEXT), @Output(EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = RETURN_CODE, value = SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = RETURN_CODE, value = FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) })
public Map<String, String> execute(@Param(value = DB_SERVER_NAME, required = true) String dbServerName, @Param(value = DB_TYPE) String dbType, @Param(value = USERNAME) String username, @Param(value = PASSWORD, encrypted = true) String password, @Param(value = INSTANCE) String instance, @Param(value = DB_PORT) String dbPort, @Param(value = DATABASE_NAME, required = true) String databaseName, @Param(value = AUTHENTICATION_TYPE) String authenticationType, @Param(value = DB_CLASS) String dbClass, @Param(value = DB_URL) String dbURL, @Param(value = COMMAND, required = true) String command, @Param(value = TRUST_ALL_ROOTS) String trustAllRoots, @Param(value = TRUST_STORE) String trustStore, @Param(value = TRUST_STORE_PASSWORD) String trustStorePassword, @Param(value = AUTH_LIBRARY_PATH) String authLibraryPath, @Param(value = DATABASE_POOLING_PROPERTIES) String databasePoolingProperties, @Param(value = RESULT_SET_TYPE) String resultSetType, @Param(value = RESULT_SET_CONCURRENCY) String resultSetConcurrency) {
dbType = defaultIfEmpty(dbType, ORACLE_DB_TYPE);
username = defaultIfEmpty(username, EMPTY);
password = defaultIfEmpty(password, EMPTY);
trustAllRoots = defaultIfEmpty(trustAllRoots, FALSE);
authenticationType = defaultIfEmpty(authenticationType, AUTH_SQL);
resultSetType = defaultIfEmpty(resultSetType, TYPE_FORWARD_ONLY);
resultSetConcurrency = defaultIfEmpty(resultSetConcurrency, CONCUR_READ_ONLY);
trustStore = defaultIfEmpty(trustStore, EMPTY);
trustStorePassword = defaultIfEmpty(trustStorePassword, EMPTY);
authLibraryPath = defaultIfEmpty(authLibraryPath, EMPTY);
instance = defaultIfEmpty(instance, EMPTY);
final List<String> preInputsValidation = validateSqlCommandInputs(dbServerName, dbType, username, password, instance, dbPort, databaseName, authenticationType, command, trustAllRoots, resultSetType, resultSetConcurrency, trustStore, trustStorePassword, authLibraryPath);
if (!preInputsValidation.isEmpty()) {
return getFailureResultsMap(StringUtils.join(preInputsValidation, NEW_LINE));
}
try {
dbType = getDbType(dbType);
final SQLInputs sqlInputs = SQLInputs.builder().dbServer(dbServerName).dbType(dbType).username(username).password(password).instance(instance).dbPort(getOrDefaultDBPort(dbPort, dbType)).dbName(defaultIfEmpty(databaseName, EMPTY)).authenticationType(authenticationType).dbClass(getOrDefaultDBClass(dbClass, dbType)).dbUrl(defaultIfEmpty(dbURL, EMPTY)).sqlCommand(command).trustAllRoots(toBoolean(trustAllRoots)).trustStore(trustStore).trustStorePassword(trustStorePassword).authLibraryPath(authLibraryPath).databasePoolingProperties(getOrDefaultDBPoolingProperties(databasePoolingProperties, EMPTY)).resultSetType(getResultSetType(resultSetType)).resultSetConcurrency(getResultSetConcurrency(resultSetConcurrency)).isNetcool(checkIsNetcool(dbType)).build();
String res = SQLCommandService.executeSqlCommand(sqlInputs);
String outputText = "";
if (ORACLE_DB_TYPE.equalsIgnoreCase(sqlInputs.getDbType()) && sqlInputs.getSqlCommand().toLowerCase().contains(DBMS_OUTPUT)) {
if (isNoneEmpty(res)) {
outputText = res;
}
res = "Command completed successfully";
} else if (sqlInputs.getLRows().size() == 0 && sqlInputs.getIUpdateCount() != -1) {
outputText = String.valueOf(sqlInputs.getIUpdateCount()) + " row(s) affected";
} else if (sqlInputs.getLRows().size() == 0 && sqlInputs.getIUpdateCount() == -1) {
outputText = "The command has no results!";
if (sqlInputs.getSqlCommand().toUpperCase().contains(SET_NOCOUNT_ON)) {
outputText = res;
}
} else {
outputText = StringUtilities.join(sqlInputs.getLRows(), NEW_LINE);
}
final Map<String, String> result = getSuccessResultsMap(res);
result.put(UPDATE_COUNT, String.valueOf(sqlInputs.getIUpdateCount()));
result.put(OUTPUT_TEXT, outputText);
return result;
} catch (Exception e) {
return getFailureResultsMap(e);
}
}
use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.
the class GetResource method execute.
@Action(name = "Get Resource", description = GET_RESOURCE_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 = NAME, description = NAME_DESC), @Output(value = DNS_NAME, description = DNS_NAME_DESC), @Output(value = RESOURCE_JSON, description = RESOURCE_JSON_DESC), @Output(value = RESOURCE_TYPE, description = RESOURCE_TYPE_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 = DCA_HOST, required = true, description = DCA_HOST_DESC) final String host, @Param(value = DCA_PORT, description = DCA_PORT_DESC) final String portInp, @Param(value = PROTOCOL, description = DCA_PROTOCOL_DESC) final String protocolInp, @Param(value = AUTH_TOKEN, required = true, encrypted = true, description = AUTH_TOKEN_DESC) final String authToken, @Param(value = REFRESH_TOKEN, encrypted = true, description = REFRESH_TOKEN_DESC) final String refreshToken, @Param(value = RESOURCE_UUID, required = true, description = RESOURCE_UUID_DESC) final String resourceUuid, @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) {
// defaults
final String port = defaultIfEmpty(portInp, DEFAULT_DCA_PORT);
final String protocol = defaultIfEmpty(protocolInp, HTTPS);
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(port, DCA_PORT).validateProtocol(protocol, PROTOCOL);
if (validator.hasErrors()) {
return getFailureResultsMap(validator.getErrors());
}
final HttpClientInputs httpClientInputs = new HttpClientInputs();
httpClientInputs.setUrl(getDcaResourceUrl(protocol, host, port, resourceUuid));
httpClientInputs.setHeaders(getAuthHeaders(authToken, refreshToken));
setProxy(httpClientInputs, proxyHost, proxyPort, proxyUsername, proxyPassword);
setSecurityInputs(httpClientInputs, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword);
setConnectionParameters(httpClientInputs, connectTimeout, socketTimeout, useCookies, keepAlive, connectionsMaxPerRoot, connectionsMaxTotal);
httpClientInputs.setFollowRedirects(TRUE);
httpClientInputs.setMethod(GET);
try {
final ObjectMapper mapper = new ObjectMapper();
final Map<String, String> httpClientResult = new HttpClientService().execute(httpClientInputs);
final String resourceJson = httpClientResult.get(RETURN_RESULT);
final JsonNode result = mapper.readTree(resourceJson);
if (parseInt(httpClientResult.get(STATUS_CODE)) != HTTP_OK) {
return getFailureResultsMap(result.toString());
}
final String dnsName = getDnsNameFromArrayNode(result.get(ATTRIBUTES));
final Map<String, String> successResultsMap = getSuccessResultsMap(SUCCESS_MESSAGE);
successResultsMap.put(NAME, result.get(NAME).asText());
successResultsMap.put(DNS_NAME, dnsName);
successResultsMap.put(RESOURCE_JSON, resourceJson);
successResultsMap.put(RESOURCE_TYPE, result.get(RESOURCE_TYPE).asText());
return successResultsMap;
} catch (Exception e) {
return getFailureResultsMap(e);
}
}
use of com.hp.oo.sdk.content.annotations.Action in project cs-actions by CloudSlang.
the class DeployTemplate method execute.
@Action(name = "Deploy Template", description = DEPLOY_TEMPLATE_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 = STATUS, description = STATUS_DESC), @Output(value = DEPLOYMENT_JSON, description = STATUS_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 = DCA_HOST, required = true, description = DCA_HOST_DESC) final String host, @Param(value = DCA_PORT, description = DCA_PORT_DESC) final String portInp, @Param(value = PROTOCOL, description = DCA_PROTOCOL_DESC) final String protocolInp, @Param(value = AUTH_TOKEN, required = true, encrypted = true, description = AUTH_TOKEN_DESC) final String authToken, @Param(value = REFRESH_TOKEN, encrypted = true, description = REFRESH_TOKEN_DESC) final String refreshToken, @Param(value = DEPLOYMENT_NAME, required = true, description = NAME_DESC) final String deploymentName, @Param(value = DEPLOYMENT_DESCRIPTION, description = DESCRIPTION_DESC) final String deploymentDesc, @Param(value = DEPLOYMENT_TEMPLATE_ID, required = true, description = TEMPLATE_ID_DESC) final String deploymentTemplateId, @Param(value = DEPLOYMENT_RESOURCES_JSON, required = true, description = RESOURCES_DESC) final String deploymentResources, @Param(value = ASYNC, description = ASYNC_DESC) final String asyncInp, @Param(value = TIMEOUT, description = TIMEOUT_DESC) final String timeoutInp, @Param(value = POLLING_INTERVAL, description = POLLING_INTERVAL_DESC) final String pollingIntervalInp, @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) {
// defaults
final String port = defaultIfEmpty(portInp, DEFAULT_DCA_PORT);
final String protocol = defaultIfEmpty(protocolInp, HTTPS);
final String asyncStr = defaultIfEmpty(asyncInp, BooleanValues.TRUE);
final String timeoutStr = defaultIfEmpty(timeoutInp, DEFAULT_TIMEOUT);
final String pollingIntervalStr = defaultIfEmpty(pollingIntervalInp, DEFAULT_POLLING_INTERVAL);
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(port, DCA_PORT).validateProtocol(protocol, PROTOCOL).validateBoolean(asyncStr, ASYNC).validateInt(timeoutStr, TIMEOUT).validateInt(pollingIntervalStr, POLLING_INTERVAL);
if (validator.hasErrors()) {
return getFailureResultsMap(validator.getErrors());
}
final HttpClientInputs httpClientInputs = new HttpClientInputs();
httpClientInputs.setUrl(getDcaDeployUrl(protocol, host, port));
httpClientInputs.setHeaders(getAuthHeaders(authToken, refreshToken));
setProxy(httpClientInputs, proxyHost, proxyPort, proxyUsername, proxyPassword);
setSecurityInputs(httpClientInputs, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword);
setConnectionParameters(httpClientInputs, connectTimeout, socketTimeout, useCookies, keepAlive, connectionsMaxPerRoot, connectionsMaxTotal);
httpClientInputs.setContentType(APPLICATION_JSON);
httpClientInputs.setFollowRedirects(BooleanValues.TRUE);
httpClientInputs.setMethod(POST);
try {
final ObjectMapper mapper = new ObjectMapper();
final List<DcaResourceModel> resources = mapper.readValue(deploymentResources, mapper.getTypeFactory().constructCollectionType(List.class, DcaResourceModel.class));
final DcaDeploymentModel dcaDeploymentModel = new DcaDeploymentModel(deploymentName, deploymentDesc, deploymentTemplateId, resources);
httpClientInputs.setBody(dcaDeploymentModel.toJson());
final Map<String, String> httpClientResult = new HttpClientService().execute(httpClientInputs);
final JsonNode result = mapper.readTree(httpClientResult.get(RETURN_RESULT));
if (Integer.parseInt(httpClientResult.get(STATUS_CODE)) != HTTP_OK) {
return getFailureResultsMap(result.toString());
}
final boolean async = toBoolean(asyncStr);
final int timeout = Integer.parseInt(timeoutStr);
final int pollingInterval = Integer.parseInt(pollingIntervalStr);
if (async) {
return getSuccessResultsMap(httpClientResult.get(RETURN_RESULT));
} else {
final long finishTime = currentTimeMillis() + SECONDS.toMillis(timeout);
final String deploymentUuid = result.get("uuid").asText();
while (true) {
Thread.sleep(SECONDS.toMillis(pollingInterval));
final Map<String, String> getDeploymentMap = new GetDeployment().execute(host, port, protocolInp, authToken, refreshToken, deploymentUuid, proxyHost, proxyPort, proxyUsername, proxyPassword, trustAllRoots, x509HostnameVerifier, trustKeystoreInp, trustPasswordInp, keystoreInp, keystorePasswordInp, connectTimeout, socketTimeout, useCookies, keepAlive, connectionsMaxPerRoot, connectionsMaxTotal);
final String getDeploymentResult = getDeploymentMap.get(RETURN_RESULT);
final String status = getDeploymentMap.get(STATUS);
if (status.equalsIgnoreCase("SUCCESS")) {
final Map<String, String> successResultsMap = getSuccessResultsMap("Successfully deployed template.");
successResultsMap.put(DEPLOYMENT_JSON, getDeploymentResult);
successResultsMap.put(STATUS, status);
return successResultsMap;
}
if (status.equalsIgnoreCase("FAILED")) {
final Map<String, String> failureResultsMap = getFailureResultsMap(getDeploymentResult, new Exception("Failed to deploy template!"));
failureResultsMap.put(STATUS, status);
return failureResultsMap;
}
if (currentTimeMillis() > finishTime) {
throw new TimeoutException("Deploy Template timeout.");
}
}
}
} catch (Exception e) {
return getFailureResultsMap(e);
}
}
Aggregations