@Override public AlertsChannel create(AlertsChannel channel) { return client .target(CHANNELS_URL) .request(APPLICATION_JSON_TYPE) .post(Entity.entity(new AlertsChannelWrapper(channel), APPLICATION_JSON_TYPE), AlertsChannelList.class) .getSingle() .orElseThrow(() -> new IllegalStateException("Failed to create channel: empty list returned")); }
@Override public List<AlertsExternalServiceCondition> list(int policyId) { return getPageable( client.target(CONDITIONS_URL).queryParam("policy_id", policyId).request(APPLICATION_JSON_TYPE), AlertsExternalServiceConditionList.class) .getList(); }
@Override public KeyTransaction getById(int keyTransactionId) { return client .target(KEY_TRANSACTION_URL) .resolveTemplate("key_transaction_id", keyTransactionId) .request(APPLICATION_JSON_TYPE) .get(KeyTransactionWrapper.class) .getKeyTransaction(); } }
private <T, LT extends ObjectList<T, LT>> LT followPageable(Link next, LT responseBody, Class<LT> responseType) { while (next != null) { Response nextResponse = client.target(next).request(APPLICATION_JSON_TYPE).get(); LT nextResponseBody = nextResponse.readEntity(responseType); responseBody = responseBody.merge(nextResponseBody); next = nextResponse.getLink("next"); } return responseBody; } }
@Override public Server getById(int serverId) { return client .target(SERVER_URL) .resolveTemplate("server_id", serverId) .request(APPLICATION_JSON_TYPE) .get(ServerWrapper.class) .getServer(); } }
@Override public AlertsChannel deleteFromPolicy(int policyId, int channelId) { return client .target(POLICY_CHANNELS_URL) .queryParam("policy_id", policyId) .queryParam("channel_id", channelId) .request(APPLICATION_JSON_TYPE) .delete(AlertsChannelWrapper.class) .getChannel(); } }
@Override public List<AlertsCondition> list(int policyId) { return getPageable( client.target(CONDITIONS_URL).queryParam("policy_id", policyId).request(APPLICATION_JSON_TYPE), AlertsConditionList.class) .getList(); }
@Override public List<AlertsChannel> list() { return getPageable( client.target(CHANNELS_URL).request(APPLICATION_JSON_TYPE), AlertsChannelList.class) .getList(); }
@Override public AlertsSyntheticsCondition create(int policyId, AlertsSyntheticsCondition syntheticsCondition) { return client .target(CONDITION_POLICY_URL) .resolveTemplate("policy_id", policyId) .request(APPLICATION_JSON_TYPE) .post(Entity.entity(new AlertsSyntheticsConditionWrapper(syntheticsCondition), APPLICATION_JSON_TYPE), AlertsSyntheticsConditionWrapper.class) .getSyntheticsCondition(); }
@Override public AlertsExternalServiceCondition create(int policyId, AlertsExternalServiceCondition condition) { return client .target(CONDITION_POLICY_URL) .resolveTemplate("policy_id", policyId) .request(APPLICATION_JSON_TYPE) .post(Entity.entity(new AlertsExternalServiceConditionWrapper(condition), APPLICATION_JSON_TYPE), AlertsExternalServiceConditionWrapper.class) .getExternalServiceCondition(); }
@Override public Optional<Application> getByName(String applicationName) { Invocation.Builder builder = client .target(APPLICATIONS_URL) .queryParam("filter[name]", applicationName) .request(APPLICATION_JSON_TYPE); return getPageable(builder, ApplicationList.class) .filter(application -> application.getName().equals(applicationName)) .getSingle(); }
@Override public AlertsExternalServiceCondition delete(int conditionId) { return client .target(CONDITION_URL) .resolveTemplate("condition_id", conditionId) .request(APPLICATION_JSON_TYPE) .delete(AlertsExternalServiceConditionWrapper.class) .getExternalServiceCondition(); } }
@Override public AlertsChannel delete(int channelId) { return client .target(CHANNEL_URL) .resolveTemplate("channel_id", channelId) .request(APPLICATION_JSON_TYPE) .delete(AlertsChannelWrapper.class) .getChannel(); }
@Override public Optional<Monitor> getByName(String monitorName) { Invocation.Builder builder = client .target(MONITORS_URL) .request(); return getPageable(builder, MonitorList.class) .filter(monitor -> monitor.getName().equals(monitorName)) .getSingle(); }
@Override public AlertsNrqlCondition delete(int conditionId) { return client .target(CONDITION_URL) .resolveTemplate("condition_id", conditionId) .request(APPLICATION_JSON_TYPE) .delete(AlertsNrqlConditionWrapper.class) .getNrqlCondition(); } }
@Override public AlertsCondition delete(int conditionId) { return client .target(CONDITION_URL) .resolveTemplate("condition_id", conditionId) .request(APPLICATION_JSON_TYPE) .delete(AlertsConditionWrapper.class) .getCondition(); } }
@Override public AlertsSyntheticsCondition update(int conditionId, AlertsSyntheticsCondition syntheticsCondition) { return client .target(CONDITION_URL) .resolveTemplate("condition_id", conditionId) .request(APPLICATION_JSON_TYPE) .put(Entity.entity(new AlertsSyntheticsConditionWrapper(syntheticsCondition), APPLICATION_JSON_TYPE), AlertsSyntheticsConditionWrapper.class) .getSyntheticsCondition(); }
@Override public Application update(int applicationId, Application application) { return client .target(APPLICATION_URL) .resolveTemplate("application_id", applicationId) .request(APPLICATION_JSON_TYPE) .put(Entity.entity(new ApplicationWrapper(application), APPLICATION_JSON_TYPE), ApplicationWrapper.class) .getApplication(); } }
@Override public AlertsExternalServiceCondition update(int conditionId, AlertsExternalServiceCondition condition) { return client .target(CONDITION_URL) .resolveTemplate("condition_id", conditionId) .request(APPLICATION_JSON_TYPE) .put(Entity.entity(new AlertsExternalServiceConditionWrapper(condition), APPLICATION_JSON_TYPE), AlertsExternalServiceConditionWrapper.class) .getExternalServiceCondition(); }
@Override public Deployment delete(int applicationId, int deploymentId) { return client .target(DEPLOYMENT_URL) .resolveTemplate("application_id", applicationId) .resolveTemplate("deployment_id", deploymentId) .request(APPLICATION_JSON_TYPE) .delete(DeploymentWrapper.class) .getDeployment(); } }