private void closeResponse(Response response) { if (response != null) { response.close(); } } }
/** * Get list of deployed Siddhi app names in a given resource node. * * @param node resource node. * @return list of deployed Siddhi app names. */ public static List<String> getDeployedApps(ResourceNode node) { feign.Response resourceResponse = null; String[] apps = new String[0]; try { resourceResponse = ResourceServiceFactory.getResourceHttpsClient(Constants.PROTOCOL + HTTPSClientUtil.generateURLHostPort(node.getHttpsInterface().getHost(), String.valueOf(node.getHttpsInterface().getPort())), node.getHttpsInterface().getUsername(), node.getHttpsInterface().getPassword()) .getSiddhiApps(); if (resourceResponse.status() == 200) { apps = new Gson().fromJson(resourceResponse.body().toString(), String[].class); } } catch (feign.FeignException e) { if (LOG.isDebugEnabled()) { LOG.debug("Error occurred while retrieving deployed Siddhi apps from " + node, e); } } finally { if (resourceResponse != null) { resourceResponse.close(); } } return Arrays.asList(apps); } }
/** * Un-deploy Siddhi app and return whether it successfully un-deployed or not. * * @param node node to be deployed. * @param siddhiAppName name of the Siddhi app. * @return a boolean stating whether the app get un-deployed or not. */ public static boolean unDeploy(ResourceNode node, String siddhiAppName) { feign.Response resourceResponse = null; try { resourceResponse = ResourceServiceFactory.getResourceHttpsClient(Constants.PROTOCOL + HTTPSClientUtil.generateURLHostPort(node.getHttpsInterface().getHost(), String.valueOf(node.getHttpsInterface().getPort())), node.getHttpsInterface().getUsername(), node.getHttpsInterface().getPassword()) .deleteSiddhiApp(siddhiAppName); return resourceResponse.status() == 200; } catch (feign.FeignException e) { if (LOG.isDebugEnabled()) { LOG.debug("Error occurred while up-deploying Siddhi app from " + node, e); } return false; } finally { if (resourceResponse != null) { resourceResponse.close(); } } }
? locationHeader.substring(locationHeader.lastIndexOf('/') + 1) : null; } else if (resourceResponse.status() == 409) { resourceResponse.close(); resourceResponse = ResourceServiceFactory.getResourceHttpsClient(Constants.PROTOCOL + HTTPSClientUtil.generateURLHostPort(node.getHttpsInterface().getHost(), } finally { if (resourceResponse != null) { resourceResponse.close();
@Override public RibbonResponse doWithRetry(RetryContext retryContext) throws IOException { Request feignRequest = null; //on retries the policy will choose the server and set it in the context //extract the server and update the request being made if (retryContext instanceof LoadBalancedRetryContext) { ServiceInstance service = ((LoadBalancedRetryContext) retryContext).getServiceInstance(); if (service != null) { feignRequest = ((RibbonRequest) request.replaceUri(reconstructURIWithServer(new Server(service.getHost(), service.getPort()), request.getUri()))).toRequest(); } } if (feignRequest == null) { feignRequest = request.toRequest(); } Response response = request.client().execute(feignRequest, options); if (retryPolicy != null && retryPolicy.retryableStatusCode(response.status())) { byte[] byteArray = response.body() == null ? new byte[]{} : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new RibbonResponseStatusCodeException(RetryableFeignLoadBalancer.this.clientName, response, byteArray, request.getUri()); } return new RibbonResponse(request.getUri(), response); } }, new LoadBalancedRecoveryCallback<RibbonResponse, Response>() {
@Override public RibbonResponse doWithRetry(RetryContext retryContext) throws IOException { Request feignRequest = null; //on retries the policy will choose the server and set it in the context //extract the server and update the request being made if (retryContext instanceof LoadBalancedRetryContext) { ServiceInstance service = ((LoadBalancedRetryContext) retryContext).getServiceInstance(); if (service != null) { feignRequest = ((RibbonRequest) request.replaceUri(reconstructURIWithServer(new Server(service.getHost(), service.getPort()), request.getUri()))).toRequest(); } } if (feignRequest == null) { feignRequest = request.toRequest(); } Response response = request.client().execute(feignRequest, options); if (retryPolicy != null && retryPolicy.retryableStatusCode(response.status())) { byte[] byteArray = response.body() == null ? new byte[]{} : StreamUtils.copyToByteArray(response.body().asInputStream()); response.close(); throw new RibbonResponseStatusCodeException(RetryableFeignLoadBalancer.this.clientName, response, byteArray, request.getUri()); } return new RibbonResponse(request.getUri(), response); } }, new LoadBalancedRecoveryCallback<RibbonResponse, Response>() {