* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
+ * Modifications Copyright (C) 2019 IBM
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
} catch (Exception e) {
defaultTimeout = 600 * 1000;
+ logger.error("Error while reading time out property" , e);
}
//continuing for checking timeout
try {
} catch (Exception e) {
defaultSocketTimeout = 60 * 1000;
+ logger.error("Error while reading socket time out property" , e);
}
//continuing for checking timeout
try {
} catch (Exception e) {
defaultPollInterval = 60 * 1000;
+ logger.error("Error while reading poll interval property" , e);
}
logger.info("Initialized Ansible Adapter");
}
// post the test request
logger.info("Posting ansible request = " + payload + " to url = " + agentUrl);
AnsibleResult testResult = postExecRequest(agentUrl, payload, user, password,ctx);
+ if (testResult != null) {
logger.info("Received response on ansible post request " + testResult.getStatusMessage());
// Process if HTTP was successful
if (testResult.getStatusCode() == 200) {
- testResult = messageProcessor.parsePostResponse(testResult.getStatusMessage());
+ testResult = messageProcessor.parsePostResponse(testResult.getStatusMessage());
} else {
- doFailure(ctx, testResult.getStatusCode(),
+ doFailure(ctx, testResult.getStatusCode(),
"Error posting request. Reason = " + testResult.getStatusMessage());
}
String output = StringUtils.EMPTY;
ctx.setAttribute(OUTPUT_ATTRIBUTE_NAME, output);
String serverIp = testResult.getServerIp();
if (StringUtils.isBlank(serverIp))
- ctx.setAttribute("ServerIP", serverIp);
+ ctx.setAttribute("ServerIP", serverIp);
else
- ctx.setAttribute("ServerIP", "");
+ ctx.setAttribute("ServerIP", "");
// Check status of test request returned by Agent
if (code == AnsibleResultCodes.PENDING.getValue()) {
- logger.info(String.format("Submission of Test %s successful.", playbookName));
- // test request accepted. We are in asynchronous case
+ logger.info(String.format("Submission of Test %s successful.", playbookName));
+ // test request accepted. We are in asynchronous case
} else {
- doFailure(ctx, code, "Request for execution of playbook rejected. Reason = " + message);
+ doFailure(ctx, code, "Request for execution of playbook rejected. Reason = " + message);
}
+ } else {
+ doFailure(ctx, code, "Ansible Test result is null");
+ }
} catch (APPCException e) {
logger.error(APPC_EXCEPTION_CAUGHT, e);
doFailure(ctx, AnsibleResultCodes.UNKNOWN_EXCEPTION.getValue(),
private AnsibleResult postExecRequest(String agentUrl, String payload, String user, String password,
SvcLogicContext ctx) {
- AnsibleResult testResult;
+ AnsibleResult testResult = null;
ConnectionBuilder httpClient = getHttpConn(defaultSocketTimeout, "");
if (!testMode) {
+ if(httpClient!=null) {
httpClient.setHttpContext(user, password);
testResult = httpClient.post(agentUrl, payload);
httpClient.close();
+ }
} else {
testResult = testServer.Post(agentUrl, payload);
}
logger.info("Querying ansible GetResult URL = " + agentUrl);
if (!testMode) {
+ if(httpClient!=null) {
httpClient.setHttpContext(user, password);
testResult = httpClient.get(agentUrl);
httpClient.close();
+ }
} else {
testResult = testServer.Get(agentUrl);
}
try {
Thread.sleep(defaultPollInterval);
} catch (InterruptedException ex) {
-
+ logger.error("Thread Interrupted Exception", ex);
+ Thread.currentThread().interrupt();
}
}