@Test public void testPut() throws IOException { thrown.expect(NullPointerException.class); ElkConnectorImpl impl = new ElkConnectorImpl(); PolicyRestAdapter adapter = new PolicyRestAdapter(); impl.put(adapter); fail("Expected exception to be thrown"); }
public boolean put(PolicyRestAdapter policyData) throws IOException, IllegalStateException { if (LOGGER.isTraceEnabled()) LOGGER.trace("ENTER"); PolicyIndexType indexType; try { String policyName = policyData.getNewFileName(); if (policyName.contains("Config_")) { policyName = policyName.replace(".Config_", ":Config_"); } else if (policyName.contains("Action_")) { policyName = policyName.replace(".Action_", ":Action_"); } else if (policyName.contains("Decision_")) { policyName = policyName.replace(".Decision_", ":Decision_"); } String[] splitPolicyName = policyName.split(":"); indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]); } catch (IllegalArgumentException e) { LOGGER.error(e); throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + e.getMessage()); } PolicyElasticData elasticData = new PolicyElasticData(policyData); JSONObject jsonObj = new JSONObject(elasticData); Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY).type(indexType.name()) .id(elasticData.getPolicyName()).refresh(true).build(); JestResult result = jestClient.execute(elkPut); if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } return result.isSucceeded(); }
ElkConnectorImpl implements ElkConnector { public boolean put(PolicyRestAdapter policyData) throws IOException, IllegalStateException { if (LOGGER.isTraceEnabled()) LOGGER.trace("ENTER"); PolicyIndexType indexType; try { String policyName = policyData.getNewFileName(); if (policyName.contains("Config_")) { policyName = policyName.replace(".Config_", ":Config_"); } else if (policyName.contains("Action_")) { policyName = policyName.replace(".Action_", ":Action_"); } else if (policyName.contains("Decision_")) { policyName = policyName.replace(".Decision_", ":Decision_"); } String[] splitPolicyName = policyName.split(":"); indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]); } catch (IllegalArgumentException e) { LOGGER.error(e); throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + e.getMessage()); } PolicyElasticData elasticData = new PolicyElasticData(policyData); JSONObject jsonObj = new JSONObject(elasticData); Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY).type(indexType.name()) .id(elasticData.getPolicyName()).refresh(true).build(); JestResult result = jestClient.execute(elkPut); if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } return result.isSucceeded(); } }
ElkConnectorImpl implements ElkConnector { public boolean put(PolicyRestAdapter policyData) throws IOException, IllegalStateException { if (LOGGER.isTraceEnabled()) LOGGER.trace("ENTER"); PolicyIndexType indexType; try { String policyName = policyData.getNewFileName(); if (policyName.contains("Config_")) { policyName = policyName.replace(".Config_", ":Config_"); } else if (policyName.contains("Action_")) { policyName = policyName.replace(".Action_", ":Action_"); } else if (policyName.contains("Decision_")) { policyName = policyName.replace(".Decision_", ":Decision_"); } String[] splitPolicyName = policyName.split(":"); indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]); } catch (IllegalArgumentException e) { LOGGER.error(e); throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + e.getMessage()); } PolicyElasticData elasticData = new PolicyElasticData(policyData); JSONObject jsonObj = new JSONObject(elasticData); Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY).type(indexType.name()) .id(elasticData.getPolicyName()).refresh(true).build(); JestResult result = jestClient.execute(elkPut); if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } return result.isSucceeded(); } ElkConnectorImpl(); }
ElkConnectorImpl implements ElkConnector { public boolean put(PolicyRestAdapter policyData) throws IOException, IllegalStateException { if (LOGGER.isTraceEnabled()) LOGGER.trace("ENTER"); PolicyIndexType indexType; try { String policyName = policyData.getNewFileName(); if (policyName.contains("Config_")) { policyName = policyName.replace(".Config_", ":Config_"); } else if (policyName.contains("Action_")) { policyName = policyName.replace(".Action_", ":Action_"); } else if (policyName.contains("Decision_")) { policyName = policyName.replace(".Decision_", ":Decision_"); } String[] splitPolicyName = policyName.split(":"); indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]); } catch (IllegalArgumentException e) { LOGGER.error(e); throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + e.getMessage()); } PolicyElasticData elasticData = new PolicyElasticData(policyData); JSONObject jsonObj = new JSONObject(elasticData); Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY).type(indexType.name()) .id(elasticData.getPolicyName()).refresh(true).build(); JestResult result = jestClient.execute(elkPut); if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } return result.isSucceeded(); } ElkConnectorImpl(); @Override JestResult search(PolicyIndexType type, String text); @Override JestResult search(PolicyIndexType type, String text, Map<String, String> filter_s); boolean put(PolicyRestAdapter policyData); @Override boolean delete(PolicyRestAdapter policyData); @Override boolean update(PolicyRestAdapter policyData); }
ElkConnectorImpl implements ElkConnector { public boolean put(PolicyRestAdapter policyData) throws IOException, IllegalStateException { if (LOGGER.isTraceEnabled()) LOGGER.trace("ENTER"); PolicyIndexType indexType; try { String policyName = policyData.getNewFileName(); if (policyName.contains("Config_")) { policyName = policyName.replace(".Config_", ":Config_"); } else if (policyName.contains("Action_")) { policyName = policyName.replace(".Action_", ":Action_"); } else if (policyName.contains("Decision_")) { policyName = policyName.replace(".Decision_", ":Decision_"); } String[] splitPolicyName = policyName.split(":"); indexType = ElkConnector.toPolicyIndexType(splitPolicyName[1]); } catch (IllegalArgumentException e) { LOGGER.error(e); throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + e.getMessage()); } PolicyElasticData elasticData = new PolicyElasticData(policyData); JSONObject jsonObj = new JSONObject(elasticData); Index elkPut = new Index.Builder(jsonObj.toString()).index(ELK_INDEX_POLICY).type(indexType.name()) .id(elasticData.getPolicyName()).refresh(true).build(); JestResult result = jestClient.execute(elkPut); if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) LOGGER.info("ElkConnector: OK: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } else { if (LOGGER.isWarnEnabled()) LOGGER.warn("ElkConnector: FAILURE: PUT operation of " + "->" + ": " + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + result.getPathToResult() + "]" + System.lineSeparator() + result.getJsonString()); } return result.isSucceeded(); } ElkConnectorImpl(); @Override JestResult search(PolicyIndexType type, String text); @Override JestResult search(PolicyIndexType type, String text, Map<String, String> filter_s); boolean put(PolicyRestAdapter policyData); @Override boolean delete(PolicyRestAdapter policyData); @Override boolean update(PolicyRestAdapter policyData);  }