use of com.cognizant.devops.platformdal.outcome.InsightsTools in project Insights by CognizantOneDevOps.
the class OutcomeServiceTest method testSaveOutcomeDefinitionRecord.
@Test(priority = 1)
public void testSaveOutcomeDefinitionRecord() throws InsightsCustomException {
try {
InsightsTools insightsMilestoneTools = outComeConfigDAL.getOutComeByToolName(toolName);
if (insightsMilestoneTools == null) {
prepareRequestData();
insightsMilestoneTools = outComeConfigDAL.getOutComeByToolName(toolName);
}
int toolId = insightsMilestoneTools.getId();
saveOutcomeJson = saveOutcomeJson.replace("toolNameeee1", String.valueOf(toolId));
JsonObject saveOutcomeConfigjson = outcomeConfigController.saveOutcomeConfig(saveOutcomeJson);
Assert.assertNotNull(saveOutcomeConfigjson);
if (saveOutcomeConfigjson.has(MilestoneConstants.STATUS) && saveOutcomeConfigjson.get(MilestoneConstants.STATUS).getAsString().equalsIgnoreCase(PlatformServiceConstants.SUCCESS)) {
JsonObject outcomeJsonList = outcomeConfigController.getAllActiveOutcome();
List<JsonObject> outcomeList = gson.fromJson(outcomeJsonList.get("data"), new TypeToken<List<JsonObject>>() {
}.getType());
Assert.assertTrue(outcomeList.stream().anyMatch(outcomeJson -> outcomeJson.get("outcomeName").getAsString().equalsIgnoreCase(outcomeNameString)));
Assert.assertTrue(saveOutcomeConfigjson.get("status").getAsString().equalsIgnoreCase(PlatformServiceConstants.SUCCESS));
} else {
Assert.fail(" Save outcome configure has issue ");
}
} catch (AssertionError e) {
Assert.fail(e.getMessage());
} catch (Exception e) {
log.error(e);
Assert.fail(e.getMessage());
}
}
use of com.cognizant.devops.platformdal.outcome.InsightsTools in project Insights by CognizantOneDevOps.
the class AgentManagementServiceImpl method registerAgent.
@Override
public String registerAgent(String toolName, String agentVersion, String osversion, String configDetails, String trackingDetails, boolean vault, boolean isWebhook, String type) throws InsightsCustomException {
try {
String agentId = null;
Gson gson = new Gson();
JsonElement jelement = gson.fromJson(configDetails.trim(), JsonElement.class);
JsonObject json = jelement.getAsJsonObject();
String labelName = getLabelName(configDetails);
Date updateDate = Timestamp.valueOf(LocalDateTime.now());
agentId = getAndValidateAgentId(toolName, json);
json.addProperty("osversion", osversion);
json.addProperty("agentVersion", agentVersion);
json.addProperty("toolName", toolName.toUpperCase());
json.addProperty("labelName", labelName);
json.get(PlatformServiceConstants.SUBSCRIBE).getAsJsonObject().addProperty("agentCtrlQueue", agentId);
if (isWebhook) {
String webhookSubscribeQueue = AgentCommonConstant.WEBHOOK_QUEUE_CONSTANT + agentId;
json.get(PlatformServiceConstants.SUBSCRIBE).getAsJsonObject().addProperty("webhookPayloadDataQueue", webhookSubscribeQueue);
json.addProperty(AgentCommonConstant.WEBHOOK_ENABLED, true);
} else if (type.equalsIgnoreCase(AgentCommonConstant.ROI_AGENT)) {
InsightsTools configs = outComeConfigDAL.getOutComeByToolName(toolName.toUpperCase());
String communicationQueue = configs.getAgentCommunicationQueue();
json.get(PlatformServiceConstants.SUBSCRIBE).getAsJsonObject().addProperty("roiExecutionQueue", communicationQueue);
json.addProperty(AgentCommonConstant.IS_ROI_AGENT, true);
}
/**
* Create agent based folder and complete basic steps using agent instance 1.
* Create folder with instance id (agent key) 2. Copy all files from agent
* folder under instance id folder 3. Replace __AGENT_KEY__ with instance id in
* service file based on OS 4. Rename InSights<agentName>Agent.sh to
* instanceId.sh name 5. Use new path in rest of the steps for agent
* registration
*/
setupAgentInstanceCreation(toolName, osversion, agentId, isWebhook);
// Update tracking.json file
if (!trackingDetails.isEmpty()) {
JsonElement trackingJsonElement = gson.fromJson(trackingDetails.trim(), JsonElement.class);
JsonObject trackingDetailsJson = trackingJsonElement.getAsJsonObject();
updateTrackingJson(toolName, trackingDetailsJson, agentId);
}
// Store secrets to vault based on agentsSecretDetails in config.json
if (vault && ApplicationConfigProvider.getInstance().getVault().isVaultEnable()) {
log.debug("-- Store secrets to vault for Agent {} --", agentId);
Map<String, String> dataMap = getToolbasedSecret(json, agentId);
prepareSecret(agentId, dataMap);
} else if (vault && !ApplicationConfigProvider.getInstance().getVault().isVaultEnable()) {
throw new InsightsCustomException("Please enable vault on servre side.");
}
// Create zip/tar file with updated config.json Zipping back the agent folder
Path agentZipPath = updateAgentConfig(toolName, json, agentId);
byte[] data = Files.readAllBytes(agentZipPath);
String fileName = agentId + AgentCommonConstant.ZIPEXTENSION;
// Sending the packet in Rabbit MQ
sendAgentPackage(data, AGENTACTION.REGISTER.name(), fileName, agentId, toolName, osversion);
performAgentAction(agentId, toolName, osversion, AGENTACTION.START.name(), agentId);
// Delete tracking.json
if (!trackingDetails.isEmpty()) {
deleteTrackingJson(agentId);
}
if (agentZipPath.toFile().exists()) {
try {
FileUtils.deleteDirectory(Paths.get(fileUnzipPath + File.separator + toolName).toFile());
FileUtils.deleteDirectory(Paths.get(fileUnzipPath + File.separator + agentId).toFile());
Files.delete(agentZipPath);
} catch (Exception e) {
log.error(e);
}
}
// register agent in DB
agentConfigDAL.saveAgentConfigFromUI(agentId, json.get("toolCategory").getAsString(), labelName, toolName, json, agentVersion, osversion, updateDate, vault, isWebhook);
return AgentCommonConstant.SUCCESS;
} catch (Exception e) {
log.error("Error while registering agent {}", toolName, e);
throw new InsightsCustomException(e.getMessage());
}
}
use of com.cognizant.devops.platformdal.outcome.InsightsTools in project Insights by CognizantOneDevOps.
the class OutComeServiceImpl method saveOutcomeConfig.
@Override
public int saveOutcomeConfig(JsonObject configJson) throws InsightsCustomException {
String outcomeName = configJson.get("outcomeName").getAsString();
InsightsOutcomeTools outcomeConfig = outComeConfigDAL.getOutComeConfigByName(outcomeName);
if (outcomeConfig != null) {
throw new InsightsCustomException("Outcome with given name already exists.");
}
InsightsOutcomeTools insightsOutcomeTools = new InsightsOutcomeTools();
insightsOutcomeTools.setOutcomeName(outcomeName);
insightsOutcomeTools.setOutcomeType(configJson.get("outcomeType").getAsString());
if (configJson.has("toolConfigJson")) {
insightsOutcomeTools.setConfigJson(configJson.get("toolConfigJson").getAsJsonObject().toString());
}
insightsOutcomeTools.setIsActive(configJson.get(CommonsAndDALConstants.ISACTIVE).getAsBoolean());
insightsOutcomeTools.setMetricUrl(configJson.get("metricUrl").getAsString());
InsightsTools insightsMilestoneTools = outComeConfigDAL.getOutComeByToolId(configJson.get("toolName").getAsInt());
insightsOutcomeTools.setInsightsTools(insightsMilestoneTools);
insightsOutcomeTools.setCreatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
insightsOutcomeTools.setRequestParameters(configJson.get("parameters").getAsJsonArray().toString());
return outComeConfigDAL.saveOutcomeConfig(insightsOutcomeTools);
}
use of com.cognizant.devops.platformdal.outcome.InsightsTools in project Insights by CognizantOneDevOps.
the class OutComeServiceImpl method getMileStoneTools.
@Override
public JsonArray getMileStoneTools() throws InsightsCustomException {
try {
List<InsightsTools> configs = outComeConfigDAL.getMileStoneTools();
Gson gson = new Gson();
JsonElement element = gson.toJsonTree(configs, new TypeToken<List<InsightsTools>>() {
}.getType());
if (!element.isJsonArray()) {
throw new InsightsCustomException("Unable to parse Json");
}
return element.getAsJsonArray();
} catch (Exception e) {
log.error("Error getting milestone list ..", e);
throw new InsightsCustomException(e.getMessage());
}
}
use of com.cognizant.devops.platformdal.outcome.InsightsTools in project Insights by CognizantOneDevOps.
the class MilestoneOutcomeTestData method prepareRequestData.
void prepareRequestData() {
InsightsTools newtool = new InsightsTools();
newtool.setCategory("APPMONITORING");
newtool.setToolName(toolName);
newtool.setToolConfigJson("{}");
newtool.setIsActive(Boolean.TRUE);
newtool.setAgentCommunicationQueue("NEWRELIC_MILESTONE_EXECUTION");
outComeConfigDAL.saveInsightsTools(newtool);
}
Aggregations