@Override public void cleanup() { if (this.client != null) { try { this.client.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } }
public void close() { try { if (client != null) { this.client.close(); } } catch (IOException e) { LOG.error("Close client error: {}", e.getMessage(), e); } }
@Override public void cleanup() { if (client != null) { try { client.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } }
@Override public void close() { try { client.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
@Override public void cleanup() { if (client != null) { try { client.close(); } catch (IOException e) { LOG.error(e.getMessage()); } } }
@Override public void cleanup() { if (client != null) { LOG.info("closing service client..."); try { client.close(); } catch (IOException e) { LOG.error("close service client failed due to {}", e.getMessage(), e); } } } }
@Override public void cleanup() { try { this.client.close(); } catch (IOException e) { LOG.error("Close client error: {}", e.getMessage(), e); } finally { super.cleanup(); } }
@Override public void cleanup() { try { this.client.getJerseyClient().destroy(); this.client.close(); } catch (IOException e) { LOG.error("Close client error: {}", e.getMessage(), e); } finally { super.cleanup(); } }
private List<HiveResourceSensitivityAPIEntity> load(JobDataMap jobDataMap) throws Exception { Map<String, Object> map = (Map<String,Object>)jobDataMap.get(EagleConfigConstants.EAGLE_SERVICE); String eagleServiceHost = (String)map.get(EagleConfigConstants.HOST); Integer eagleServicePort = Integer.parseInt(map.get(EagleConfigConstants.PORT).toString()); String username = map.containsKey(EagleConfigConstants.USERNAME) ? (String)map.get(EagleConfigConstants.USERNAME) : null; String password = map.containsKey(EagleConfigConstants.PASSWORD) ? (String)map.get(EagleConfigConstants.PASSWORD) : null; // load from eagle database LOG.info("Load hive resource sensitivity information from eagle service " + eagleServiceHost + ":" + eagleServicePort); IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password); String query = "HiveResourceSensitivityService[]{*}"; GenericServiceAPIResponseEntity<HiveResourceSensitivityAPIEntity> response = client.search().pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) throw new IllegalStateException(response.getException()); return response.getObj(); } }
@Override public List<MLModelAPIEntity> findMLModelByContext(String user, String algorithm) { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = MLConstants.ML_MODEL_SERVICE_NAME + "[@user=\"" + user + "\" AND @algorithm=\"" + algorithm + "\"]{*}"; GenericServiceAPIResponseEntity<MLModelAPIEntity> response = client.search().startTime(0) .endTime(10 * DateUtils.MILLIS_PER_DAY) .pageSize(Integer.MAX_VALUE) .query(query) .send(); if(!response.isSuccess()) { LOG.error(String.format("Failed to get model for user: %s, algorithm: %s, due to: %s",user,algorithm,response.getException())); } client.close(); return response.getObj(); } catch (Exception ex) { LOG.info("Got an exception when query machinelearning model service ", ex); throw new IllegalStateException(ex); } } }
@Override public List<GenericAuditEntity> findSiteAudit(String site) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"AlertDataSourceService\" AND @site=\"" + site + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findUserServiceAudit(String userID) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@userID=\"" + userID + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findPolicyAudit(String site, String application) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"AlertDefinitionService\" AND @site=\"" + site + "\" AND @application=\"" + application + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findServiceAudit(String serviceName) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"" + serviceName + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findDataSourceAudit(String application) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"AlertDataSourceService\" AND @application=\"" + application + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findServiceAuditByUser(String serviceName, String userID) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"" + serviceName + "\" AND @userID=\"" + userID + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findServiceAuditByAction(String serviceName, String action) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@serviceName=\"" + serviceName + "\" AND @actionTaken=\"" + action + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
@Override public List<GenericAuditEntity> findUserServiceAuditByAction(String userID, String action) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@userID=\"" + userID + "\" AND @actionTaken=\"" + action + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } } }
@Test public void testAsyncSender() throws IOException, EagleServiceClientException, ExecutionException, InterruptedException { EagleServiceAsyncClient asyncClient = client.async(); Future<GenericServiceAPIResponseEntity<String>> future1 = asyncClient.create(Arrays.asList(newEntity())); GenericServiceAPIResponseEntity<String> response1 = future1.get(); Assert.assertTrue(response1.isSuccess()); Future<GenericServiceAPIResponseEntity<String>> future2 = asyncClient.update(Arrays.asList(newEntity())); GenericServiceAPIResponseEntity<String> response2 = future2.get(); Assert.assertTrue(response2.isSuccess()); Future<GenericServiceAPIResponseEntity<String>> future3 = asyncClient.delete(Arrays.asList(newEntity())); GenericServiceAPIResponseEntity<String> response3 = future3.get(); Assert.assertTrue(response3.isSuccess()); client.close(); }
@Test public void testBatchSender() throws IOException, EagleServiceClientException { client.batch(2) .send(newEntity()) .send(newEntity()) .send(newEntity()); client.close(); }