Search in sources :

Example 1 with GraphDBHandler

use of com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler in project Insights by CognizantOneDevOps.

the class WebhookEngineTestData method readNeo4JData.

@SuppressWarnings("rawtypes")
public static Map readNeo4JData(String nodeName, String compareFlag) {
    Map map = null;
    ObjectMapper mapper = new ObjectMapper();
    GraphDBHandler dbHandler = new GraphDBHandler();
    String query = "MATCH (n:" + nodeName + ") where n." + compareFlag + "='8ea6c42b96d5c0ffdaf3622720450e2d5def75e6' return n";
    GraphResponse neo4jResponse;
    try {
        neo4jResponse = dbHandler.executeCypherQuery(query);
        JsonElement tooldataObject = neo4jResponse.getJson().get("results").getAsJsonArray().get(0).getAsJsonObject().get("data").getAsJsonArray().get(0).getAsJsonObject().get("row");
        String finalJson = tooldataObject.toString().replace("[", "").replace("]", "");
        // Gson gson = new Gson();
        // map = gson.fromJson(finalJson, Map.class); GraphDB
        map = mapper.readValue(finalJson, Map.class);
    } catch (Exception e) {
        LOG.error(e);
    }
    return map;
}
Also used : GraphDBHandler(com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler) GraphResponse(com.cognizant.devops.platformcommons.dal.neo4j.GraphResponse) JsonElement(com.google.gson.JsonElement) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 2 with GraphDBHandler

use of com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler in project Insights by CognizantOneDevOps.

the class EngineAggregatorCorelationModuleTest method testCorrelation.

@Test(priority = 3)
public void testCorrelation() {
    GraphDBHandler dbHandler = new GraphDBHandler();
    String query = "MATCH (a)<-[r:TEST_FROM_GIT_TO_JENKINS]-(b) where a.scmcommitId=\"CM-7569369619\" and b.commitId='CM-7569369619' return count(a) as Total";
    GraphResponse neo4jResponse;
    try {
        neo4jResponse = dbHandler.executeCypherQuery(query);
        String finalJson = neo4jResponse.getJson().get("results").getAsJsonArray().get(0).getAsJsonObject().get("data").getAsJsonArray().get(0).getAsJsonObject().get("row").toString().replace("[", "").replace("]", "");
        /* Assert on Node Relationship */
        log.debug("finalJson  {} ", finalJson);
        // "true"
        Assert.assertTrue(Integer.parseInt(finalJson) > 0);
    } catch (InsightsCustomException | AssertionError e) {
        log.error("InsightsCustomException : or AssertionError " + e);
    }
}
Also used : GraphDBHandler(com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) GraphResponse(com.cognizant.devops.platformcommons.dal.neo4j.GraphResponse) Test(org.testng.annotations.Test)

Example 3 with GraphDBHandler

use of com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler in project Insights by CognizantOneDevOps.

the class EngineAggregatorCorelationModuleTest method cleanUp.

@AfterClass
public void cleanUp() {
    try {
        agentConfigDAL.deleteAgentConfigurations("JENKINSTEST8800");
        agentConfigDAL.deleteAgentConfigurations("GITTEST8800");
        correlationConfigDAL.deleteCorrelationConfig("TEST_FROM_GIT_TO_JENKINS");
        configFilesDAL.deleteConfigurationFile("DataEnrichmentTest");
    } catch (InsightsCustomException e1) {
        log.error(e1);
    }
    ApplicationConfigProvider.getInstance().getCorrelations().setBatchSize(2000);
    ApplicationConfigProvider.getInstance().getCorrelations().setCorrelationFrequency(3);
    ApplicationConfigProvider.getInstance().getCorrelations().setCorrelationWindow(48);
    /* Cleaning Neo4J */
    GraphDBHandler dbHandler = new GraphDBHandler();
    String query = "MATCH p=()-[r:TEST_FROM_GIT_TO_JENKINS]->() delete p";
    try {
        dbHandler.executeCypherQuery(query);
        dbHandler.executeCypherQuery("MATCH (n:JENKINS_UNTEST) DETACH DELETE n");
        dbHandler.executeCypherQuery("MATCH (n:GIT_UNTEST) DETACH DELETE n");
    } catch (InsightsCustomException e) {
        log.error("InsightsCustomException : " + e.toString());
    }
}
Also used : GraphDBHandler(com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) AfterClass(org.testng.annotations.AfterClass)

Example 4 with GraphDBHandler

use of com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler in project Insights by CognizantOneDevOps.

the class WebhookEngineTest method cleanUp.

/*@Test(priority = 8)
	public void testEngineAgreegateException() throws Exception {
		WebHookConfig webhookConfig = new WebHookConfig();
		webhookConfig.setResponseTemplate(webhookEngineTestData.responseTemplate);
		webhookConfig.setDynamicTemplate(webhookEngineTestData.dynamicTemplate);
		webhookConfig.setToolName(webhookEngineTestData.toolName);
		webhookConfig.setWebHookName(webhookEngineTestData.webhookNameException);
		webhookConfig.setMQChannel("");
		webhookConfig.setSubscribeStatus(true);
		webhookConfig.setIsUpdateRequired(webhookEngineTestData.isUpdateRequired);
		webhookConfig.setFieldUsedForUpdate(webhookEngineTestData.fieldUsedForUpdate);
		webhookConfig.setDataFormat(p.getProperty("dataFormat"));
		webhookConfig.setWebhookDerivedConfig(webhookEngineTestData.derivedOperationsArray);
		webhookConfigDAL.saveWebHookConfiguration(webhookConfig);
		WebHookEngineAggregatorModule em = new WebHookEngineAggregatorModule();
		em.run();
	}*/
@AfterClass
public void cleanUp() {
    // Cleaning Postgre
    webhookConfigDAL.deleteWebhookConfigurations(p.getProperty("webhookName"));
    // webhookConfigDAL.deleteWebhookConfigurations(webhookEngineTestData.webhookNameException);
    // Cleaning Neo4J
    GraphDBHandler dbHandler = new GraphDBHandler();
    String query = "MATCH (p:" + webhookEngineTestData.labelName + ") where p.webhookName='" + webhookEngineTestData.webhookName + "' delete p";
    String queryDeleteHeathData = "MATCH (p:" + webhookEngineTestData.WEBHOOK_SUBSCRIBER_HEALTH_ROUTING_KEY + ") where p.instanceName='" + webhookEngineTestData.healthMessageInstanceName + "' delete p";
    try {
        dbHandler.executeCypherQuery(query);
        dbHandler.executeCypherQuery(queryDeleteHeathData);
    } catch (InsightsCustomException e) {
        log.error("InsightsCustomException : " + e.toString());
    }
}
Also used : GraphDBHandler(com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) AfterClass(org.testng.annotations.AfterClass)

Example 5 with GraphDBHandler

use of com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler in project Insights by CognizantOneDevOps.

the class GraphdbCorrelationConfiguration method checkQuery.

private boolean checkQuery(String query) {
    GraphDBHandler dbHandler = new GraphDBHandler();
    GraphResponse neo4jResponse;
    try {
        neo4jResponse = dbHandler.executeCypherQuery(query);
        String finalJson = neo4jResponse.getJson().get("results").getAsJsonArray().get(0).getAsJsonObject().get("data").getAsJsonArray().get(0).getAsJsonObject().get("row").toString().replace("[", "").replace("]", "");
        log.debug("finalJson  {} ", finalJson);
        if (Integer.parseInt(finalJson) > 0) {
            return true;
        }
    } catch (InsightsCustomException | AssertionError e) {
        log.error("InsightsCustomException : or AssertionError {}", e);
    }
    return false;
}
Also used : GraphDBHandler(com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) GraphResponse(com.cognizant.devops.platformcommons.dal.neo4j.GraphResponse)

Aggregations

GraphDBHandler (com.cognizant.devops.platformcommons.dal.neo4j.GraphDBHandler)42 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)36 GraphResponse (com.cognizant.devops.platformcommons.dal.neo4j.GraphResponse)26 JsonObject (com.google.gson.JsonObject)19 JsonArray (com.google.gson.JsonArray)15 JsonElement (com.google.gson.JsonElement)12 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)6 Map (java.util.Map)4 File (java.io.File)3 JobExecutionException (org.quartz.JobExecutionException)3 KeyFactory (java.security.KeyFactory)2 PrivateKey (java.security.PrivateKey)2 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)2 List (java.util.List)2 Cipher (javax.crypto.Cipher)2 AfterClass (org.testng.annotations.AfterClass)2 BeforeClass (org.testng.annotations.BeforeClass)2 Test (org.testng.annotations.Test)2 LoadFile (com.cognizant.devops.platformauditing.util.LoadFile)1