use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cloud-slang by CloudSlang.
the class ActionStepsTest method doJavaActionSetKeyOnNonSerializableSessionTest.
@Test(timeout = DEFAULT_TIMEOUT)
public void doJavaActionSetKeyOnNonSerializableSessionTest() {
// prepare doAction arguments
final RunEnvironment runEnv = new RunEnvironment();
HashMap<String, Map<String, Object>> nonSerializableExecutionData = new HashMap<>();
HashMap<String, Object> globalSessionObjectData = new HashMap<>();
GlobalSessionObject<NonSerializableObject> sessionObject = new GlobalSessionObject<>();
NonSerializableObject employee = new NonSerializableObject("John");
sessionObject.setResource(new ContentTestActions.NonSerializableSessionResource(employee));
globalSessionObjectData.put("name", sessionObject);
nonSerializableExecutionData.put(ExecutionParametersConsts.GLOBAL_SESSION_OBJECT, globalSessionObjectData);
Map<String, Value> initialCallArguments = new HashMap<>();
initialCallArguments.put("value", ValueFactory.create("David"));
runEnv.putCallArguments(initialCallArguments);
// invoke doAction
actionSteps.doAction(executionRuntimeServicesMock, runEnv, nonSerializableExecutionData, 2L, JAVA, ContentTestActions.class.getName(), "setNameOnNonSerializableSession", GAV_DEFAULT, null, true, DEPENDENCIES_DEFAULT, seqSteps, null, null);
Map<String, Object> globalSessionObject = nonSerializableExecutionData.get(GLOBAL_SESSION_OBJECT);
Assert.assertTrue(globalSessionObject.containsKey("name"));
@SuppressWarnings("unchecked") GlobalSessionObject<NonSerializableObject> updatedSessionObject = (GlobalSessionObject<NonSerializableObject>) globalSessionObject.get("name");
NonSerializableObject nonSerializableObject = updatedSessionObject.get();
String actualName = nonSerializableObject.getName();
assertEquals("David", actualName);
}
use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.
the class AddMember method execute.
@Action(name = ADD_MEMBER, description = ADD_MEMBER_DESCRIPTION, outputs = { @Output(RETURN_RESULT), @Output(STATUS_CODE), @Output(RETURN_CODE), @Output(EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) })
public Map<String, String> execute(@Param(value = HOST, description = HOST_DESCRIPTION, required = true) String hostName, @Param(value = PROTOCOL, description = PROTOCOL_DESCRIPTION) String protocol, @Param(value = AUTH_TOKEN, description = AUTH_TOKEN_DESCRIPTION, required = true) String authToken, @Param(value = SAFE_URL_ID, description = SAFE_URL_ID_DESCRIPTION, required = true) String safeUrlId, @Param(value = MEMBER_NAME, description = MEMBER_NAME_DESCRIPTION, required = true) String memberName, @Param(value = SEARCH_IN, description = SEARCH_IN_DESCRIPTION) String searchIn, @Param(value = MEMBERSHIP_EXPIRATION_DATE, description = MEMBERSHIP_EXPIRATION_DATE_DESCRIPTION) String membershipExpirationDate, @Param(value = PERMISSIONS, description = PERMISSIONS_DESCRIPTION) String permissions, @Param(value = IS_READ_ONLY, description = IS_READ_ONLY_DESCRIPTION) String isReadOnly, @Param(value = MEMBER_TYPE, description = MEMBER_TYPE_DESCRIPTION) String memberType, @Param(value = PROXY_HOST, description = PROXY_HOST_DESCRIPTION) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESCRIPTION) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESCRIPTION) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESCRIPTION) String proxyPassword, @Param(value = TLS_VERSION, description = TLS_VERSION_DESCRIPTION) String tlsVersion, @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESCRIPTION) String allowedCiphers, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESCRIPTION) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESCRIPTION) String x509HostnameVerifier, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESCRIPTION) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESCRIPTION) String trustPassword, @Param(value = KEYSTORE, description = KEYSTORE_DESCRIPTION) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESCRIPTION) String keystorePassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESCRIPTION) String connectTimeout, @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESCRIPTION) String executionTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESCRIPTION) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESCRIPTION) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESCRIPTION) String connectionsMaxTotal, @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) {
try {
validateProtocol(protocol);
JSONObject body = new JSONObject();
body.put(MEMBER_NAME, memberName);
body.put(SEARCH_IN, searchIn);
if (!StringUtils.isEmpty(membershipExpirationDate))
body.put(MEMBERSHIP_EXPIRATION_DATE, membershipExpirationDate);
JSONObject permissionsJson = new JSONObject();
if (!StringUtils.isEmpty(permissions))
Arrays.stream(permissions.trim().split(SEMICOLON)).map(permission -> permission.split(EQUALS)).forEach(permission -> permissionsJson.put(permission[0], permission[1]));
body.put(PERMISSIONS, permissionsJson);
body.put(IS_READ_ONLY, isReadOnly);
body.put(MEMBER_TYPE, memberType);
Map<String, String> result = new HttpClientPostAction().execute(protocol + PROTOCOL_DELIMITER + hostName + ADD_MEMBER_ENDPOINT + safeUrlId + MEMBERS, ANONYMOUS, EMPTY, EMPTY, EMPTY, proxyHost, proxyPort, proxyUsername, proxyPassword, tlsVersion, allowedCiphers, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal, EMPTY, EMPTY, CONTENT_TYPE + APPLICATION_JSON + COMMA + AUTHORIZATION + authToken, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, body.toString(), APPLICATION_JSON, EMPTY, connectTimeout, EMPTY, executionTimeout, sessionCookies, sessionConnectionPool);
processHttpResult(result);
return result;
} catch (Exception exception) {
return OutputUtilities.getFailureResultsMap(exception);
}
}
use of com.hp.oo.sdk.content.plugin.GlobalSessionObject 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.plugin.GlobalSessionObject in project cs-actions by CloudSlang.
the class CounterProcessor method init.
public void init(String to, String from, String by, boolean reset, GlobalSessionObject<Map<String, Object>> session) throws CounterImplException {
/*
* If the session resource is not ini
*/
if (session.get() == null) {
session.setResource(new CounterSessionResource(new HashMap<String, Object>()));
}
Map<String, Object> sessionMap = session.get();
try {
start = Long.parseLong(from.trim());
end = Long.parseLong(to.trim());
if (by == null || by.length() == 0)
increment = 1;
else
try {
increment = Integer.parseInt(by);
} catch (Exception e) {
increment = 1;
}
} catch (Exception e) {
throw new CounterImplException("Start or end is not a long integer, or by is not an integer.\nfrom: " + from + "\nto: " + to + "\nby:" + by);
}
try {
index = (Integer) sessionMap.get(INDEX);
} catch (Exception e) {
index = 0;
}
if (index == 0 && initialized(session)) {
sessionMap.put(INDEX, 0);
}
// ok, now push data into context
if (!initialized(session)) {
sessionMap.put(INDEX, 0);
}
// pull data from context
this.index = (Integer) sessionMap.get(INDEX);
}
use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.
the class CounterProcessor method init.
public void init(String to, String from, String by, boolean reset, GlobalSessionObject<Map<String, Object>> session) throws Exception {
/*
* If the session resource is not ini
*/
if (session.get() == null) {
session.setResource(new CounterSessionResource(new HashMap<>()));
}
Map<String, Object> sessionMap = session.get();
try {
start = Long.parseLong(from.trim());
end = Long.parseLong(to.trim());
if (by == null || by.length() == 0)
increment = 1;
else
try {
increment = Integer.parseInt(by);
} catch (Exception e) {
increment = 1;
}
} catch (Exception e) {
throw new CounterImplException("Start or end is not a long integer, or by is not an integer.\nfrom: " + from + "\nto: " + to + "\nby:" + by);
}
try {
index = (Integer) sessionMap.get(INDEX);
} catch (Exception e) {
index = 0;
}
if (index == 0 && initialized(session)) {
sessionMap.put(INDEX, 0);
}
// ok, now push data into context
if (!initialized(session)) {
sessionMap.put(INDEX, 0);
}
// pull data from context
this.index = (Integer) sessionMap.get(INDEX);
}
Aggregations