Refine search
@Override protected CreateNetworkResponse execute(CreateNetworkCmd command) { WebTarget webResource = getBaseResource().path("/networks/create"); LOGGER.trace("POST: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON) .post(entity(command, MediaType.APPLICATION_JSON), CreateNetworkResponse.class); } }
@Override public RegistryClientEntity createRegistryClient(final RegistryClientEntity registryClient) throws NiFiClientException, IOException { if (registryClient == null) { throw new IllegalArgumentException("Registry client entity cannot be null"); } return executeAction("Error creating registry client", () -> { final WebTarget target = controllerTarget.path("registry-clients"); return getRequestBuilder(target).post( Entity.entity(registryClient, MediaType.APPLICATION_JSON), RegistryClientEntity.class ); }); }
@Override public NodeEntity offloadNode(final String nodeId, final NodeEntity nodeEntity) throws NiFiClientException, IOException { if (StringUtils.isBlank(nodeId)) { throw new IllegalArgumentException("Node ID cannot be null or empty"); } if (nodeEntity == null) { throw new IllegalArgumentException("Node entity cannot be null"); } return executeAction("Error offloading node", () -> { final WebTarget target = controllerTarget.path("cluster/nodes/" + nodeId); return getRequestBuilder(target).put(Entity.entity(nodeEntity, MediaType.APPLICATION_JSON), NodeEntity.class); }); }
@Override protected CreateVolumeResponse execute(CreateVolumeCmd command) { WebTarget webResource = getBaseResource().path("/volumes/create"); LOGGER.trace("POST: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON) .post(entity(command, MediaType.APPLICATION_JSON), CreateVolumeResponse.class); } }
@Override Map<String, Object> userFromResource(String externalToken) { MultivaluedMap<String, String> formData = getMultivaluedMapImpl(); formData.add("grant_type", "urn:pingidentity.com:oauth2:grant_type:validate_bearer"); formData.add("client_id", clientId); formData.add("client_secret", clientSecret); formData.add("token", externalToken); JsonNode node = client.target(apiUrl).request() .post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE), JsonNode.class); String rawEmail = node.get("access_token").get("subject").asText(); Map<String, Object> userMap = new HashMap<String, Object>(); userMap.put("expiration", node.get("expires_in").asLong()); userMap.put("username", pingUsernameFrom(rawEmail)); userMap.put("name", "pinguser"); userMap.put("email", rawEmail); return userMap; }
@Override public NodeEntity disconnectNode(final String nodeId, final NodeEntity nodeEntity) throws NiFiClientException, IOException { if (StringUtils.isBlank(nodeId)) { throw new IllegalArgumentException("Node ID cannot be null or empty"); } if (nodeEntity == null) { throw new IllegalArgumentException("Node entity cannot be null"); } return executeAction("Error disconnecting node", () -> { final WebTarget target = controllerTarget.path("cluster/nodes/" + nodeId); return getRequestBuilder(target).put(Entity.entity(nodeEntity, MediaType.APPLICATION_JSON), NodeEntity.class); }); }
@Override public TokenResult refreshAccessToken(final String refreshToken) { refreshTokenProperties.put(OAuth2Parameters.REFRESH_TOKEN, refreshToken); final Form form = new Form(); for (final Map.Entry<String, String> entry : refreshTokenProperties.entrySet()) { form.param(entry.getKey(), entry.getValue()); } final Response response = client.target(refreshTokenUri) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (response.getStatus() != 200) { throw new ProcessingException(LocalizationMessages.ERROR_FLOW_REQUEST_REFRESH_TOKEN(response.getStatus())); } this.tokenResult = response.readEntity(TokenResult.class); return tokenResult; }
@Override public NodeEntity connectNode(final String nodeId, final NodeEntity nodeEntity) throws NiFiClientException, IOException { if (StringUtils.isBlank(nodeId)) { throw new IllegalArgumentException("Node ID cannot be null or empty"); } if (nodeEntity == null) { throw new IllegalArgumentException("Node entity cannot be null"); } return executeAction("Error connecting node", () -> { final WebTarget target = controllerTarget.path("cluster/nodes/" + nodeId); return getRequestBuilder(target).put(Entity.entity(nodeEntity, MediaType.APPLICATION_JSON), NodeEntity.class); }); }
@Override public TokenResult finish(final String authorizationCode, final String state) { if (!this.authorizationProperties.get(OAuth2Parameters.STATE).equals(state)) { throw new IllegalArgumentException(LocalizationMessages.ERROR_FLOW_WRONG_STATE()); } accessTokenProperties.put(OAuth2Parameters.CODE, authorizationCode); final Form form = new Form(); for (final Map.Entry<String, String> entry : accessTokenProperties.entrySet()) { form.param(entry.getKey(), entry.getValue()); } final Response response = client.target(accessTokenUri) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); if (response.getStatus() != 200) { throw new ProcessingException(LocalizationMessages.ERROR_FLOW_REQUEST_ACCESS_TOKEN(response.getStatus())); } this.tokenResult = response.readEntity(TokenResult.class); return tokenResult; }
@Override public ProcessGroupEntity createProcessGroup(final String parentGroupdId, final ProcessGroupEntity entity) throws NiFiClientException, IOException { if (StringUtils.isBlank(parentGroupdId)) { throw new IllegalArgumentException("Parent process group id cannot be null or blank"); } if (entity == null){ throw new IllegalArgumentException("Process group entity cannot be null"); } return executeAction("Error creating process group", () -> { final WebTarget target = processGroupsTarget .path("{id}/process-groups") .resolveTemplate("id", parentGroupdId); return getRequestBuilder(target).post( Entity.entity(entity, MediaType.APPLICATION_JSON_TYPE), ProcessGroupEntity.class ); }); }
public <V> T put(final String queryResourceUrl, final V request) { CompletableFuture<T> result = new CompletableFuture<>(); final WebTarget webResource = client.target(queryResourceUrl); return buildResponse(webResource .request(accept) .accept(accept) .put(Entity.entity(request, contentType),String.class)); } public T delete(final String queryResourceUrl) {
@Override public VersionedFlowUpdateRequestEntity updateVersionControlInfo(final String processGroupId, final VersionControlInformationEntity entity) throws IOException, NiFiClientException { if (StringUtils.isBlank(processGroupId)) { throw new IllegalArgumentException("Process group id cannot be null or blank"); } if (entity == null) { throw new IllegalArgumentException("Version control information entity cannot be null"); } return executeAction("Error updating version control information", () -> { final WebTarget target = versionsTarget .path("update-requests/process-groups/{id}") .resolveTemplate("id", processGroupId); return getRequestBuilder(target).post( Entity.entity(entity, MediaType.APPLICATION_JSON_TYPE), VersionedFlowUpdateRequestEntity.class ); }); }
@Override public boolean post(String message) { Map<String, String> payload = ImmutableMap.of( "text", message, "username", slackConfig.username(), "icon_emoji", slackConfig.emoji() ); try { Form form = new Form().param("payload", mapper.writeValueAsString(payload)); this.target .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); return true; } catch (IOException ex) { LOG.warn("Can't post message to slack", ex); return false; } }