List of usage examples for org.apache.http.client.utils URIBuilder setParameter
public URIBuilder setParameter(final String param, final String value)
From source file:org.apache.ambari.server.controller.metrics.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateResources_params_category3() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("flume_ganglia_data.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); Map<String, Map<String, PropertyInfo>> gangliaPropertyIds = PropertyHelper .getMetricPropertyIds(Resource.Type.HostComponent); GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(gangliaPropertyIds, streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID); // flume//from w ww . jav a 2 s . c om Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER"); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(FLUME_CATEGORY3, new TemporalInfoImpl(10L, 20L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(FLUME_CATEGORY3), temporalInfoMap); Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size()); List<String> metricsRegexes = new ArrayList<String>(); metricsRegexes.add("metrics/flume/$1/CHANNEL/$2/"); metricsRegexes.add(FLUME_CHANNEL_CAPACITY_PROPERTY); String metricsList = getMetricsRegexes(metricsRegexes, gangliaPropertyIds, "FLUME_HANDLER"); URIBuilder expectedUri = new URIBuilder(); expectedUri.setScheme((configuration.isGangliaSSL() ? "https" : "http")); expectedUri.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); expectedUri.setPath("/cgi-bin/rrd.py"); expectedUri.setParameter("c", "HDPFlumeServer,HDPSlaves"); expectedUri.setParameter("h", "ip-10-39-113-33.ec2.internal"); expectedUri.setParameter("m", metricsList); expectedUri.setParameter("s", "10"); expectedUri.setParameter("e", "20"); expectedUri.setParameter("r", "1"); URIBuilder actualUri = new URIBuilder(streamProvider.getLastSpec()); Assert.assertEquals(expectedUri.getScheme(), actualUri.getScheme()); Assert.assertEquals(expectedUri.getHost(), actualUri.getHost()); Assert.assertEquals(expectedUri.getPath(), actualUri.getPath()); Assert.assertTrue(isUrlParamsEquals(actualUri, expectedUri)); Assert.assertEquals(11, PropertyHelper.getProperties(resource).size()); Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY)); }
From source file:org.apache.ambari.server.controller.metrics.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateResources_params_category4() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("flume_ganglia_data.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); Map<String, Map<String, PropertyInfo>> gangliaPropertyIds = PropertyHelper .getMetricPropertyIds(Resource.Type.HostComponent); GangliaPropertyProvider propertyProvider = new GangliaHostComponentPropertyProvider(gangliaPropertyIds, streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID); // flume//from www.j av a 2s . c o m Resource resource = new ResourceImpl(Resource.Type.HostComponent); resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal"); resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER"); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(FLUME_CATEGORY4, new TemporalInfoImpl(10L, 20L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(FLUME_CATEGORY4), temporalInfoMap); Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size()); List<String> metricsRegexes = new ArrayList<String>(); metricsRegexes.add("metrics/flume/$1/CHANNEL/$2"); metricsRegexes.add(FLUME_CHANNEL_CAPACITY_PROPERTY); String metricsList = getMetricsRegexes(metricsRegexes, gangliaPropertyIds, "FLUME_HANDLER"); URIBuilder expectedUri = new URIBuilder(); expectedUri.setScheme((configuration.isGangliaSSL() ? "https" : "http")); expectedUri.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); expectedUri.setPath("/cgi-bin/rrd.py"); expectedUri.setParameter("c", "HDPFlumeServer,HDPSlaves"); expectedUri.setParameter("h", "ip-10-39-113-33.ec2.internal"); expectedUri.setParameter("m", metricsList); expectedUri.setParameter("s", "10"); expectedUri.setParameter("e", "20"); expectedUri.setParameter("r", "1"); URIBuilder actualUri = new URIBuilder(streamProvider.getLastSpec()); Assert.assertEquals(expectedUri.getScheme(), actualUri.getScheme()); Assert.assertEquals(expectedUri.getHost(), actualUri.getHost()); Assert.assertEquals(expectedUri.getPath(), actualUri.getPath()); Assert.assertTrue(isUrlParamsEquals(actualUri, expectedUri)); Assert.assertEquals(11, PropertyHelper.getProperties(resource).size()); Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY)); }
From source file:org.finra.herd.tools.common.databridge.DataBridgeWebClient.java
/** * Retrieves S3 key prefix from the registration server. * * @param manifest the manifest file information * @param businessObjectDataVersion the business object data version (optional) * @param createNewVersion if not set, only initial version of the business object data is allowed to be created. This parameter is ignored, when the * business object data version is specified. * * @return the S3 key prefix//from w w w. ja v a 2 s .c o m * @throws IOException if an I/O error was encountered * @throws JAXBException if a JAXB error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ protected S3KeyPrefixInformation getS3KeyPrefix(DataBridgeBaseManifestDto manifest, Integer businessObjectDataVersion, Boolean createNewVersion) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { LOGGER.info("Retrieving S3 key prefix from the registration server..."); StringBuilder uriPathBuilder = new StringBuilder(151); uriPathBuilder.append(HERD_APP_REST_URI_PREFIX + "/businessObjectData"); // The namespace is optional. If not specified, do not add to the REST URI. if (StringUtils.isNotBlank(manifest.getNamespace())) { uriPathBuilder.append("/namespaces/").append(manifest.getNamespace()); } uriPathBuilder.append("/businessObjectDefinitionNames/").append(manifest.getBusinessObjectDefinitionName()); uriPathBuilder.append("/businessObjectFormatUsages/").append(manifest.getBusinessObjectFormatUsage()); uriPathBuilder.append("/businessObjectFormatFileTypes/").append(manifest.getBusinessObjectFormatFileType()); uriPathBuilder.append("/businessObjectFormatVersions/").append(manifest.getBusinessObjectFormatVersion()); uriPathBuilder.append("/s3KeyPrefix"); String uriPath = uriPathBuilder.toString(); URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()) .setHost(regServerAccessParamsDto.getRegServerHost()) .setPort(regServerAccessParamsDto.getRegServerPort()).setPath(uriPath) .setParameter("partitionKey", manifest.getPartitionKey()) .setParameter("partitionValue", manifest.getPartitionValue()) .setParameter("createNewVersion", createNewVersion.toString()); if (!CollectionUtils.isEmpty(manifest.getSubPartitionValues())) { uriBuilder.setParameter("subPartitionValues", herdStringHelper.join(manifest.getSubPartitionValues(), "|", "\\")); } if (businessObjectDataVersion != null) { uriBuilder.setParameter("businessObjectDataVersion", businessObjectDataVersion.toString()); } if (StringUtils.isNotBlank(manifest.getStorageName())) { uriBuilder.setParameter("storageName", manifest.getStorageName()); } S3KeyPrefixInformation s3KeyPrefixInformation; try (CloseableHttpClient client = httpClientHelper.createHttpClient( regServerAccessParamsDto.isTrustSelfSignedCertificate(), regServerAccessParamsDto.isDisableHostnameVerification())) { HttpGet request = new HttpGet(uriBuilder.build()); request.addHeader("Accepts", DEFAULT_ACCEPT); // If SSL is enabled, set the client authentication header. if (regServerAccessParamsDto.isUseSsl()) { request.addHeader(getAuthorizationHeader()); } LOGGER.info(String.format(" HTTP GET URI: %s", request.getURI().toString())); LOGGER.info(String.format(" HTTP GET Headers: %s", Arrays.toString(request.getAllHeaders()))); s3KeyPrefixInformation = getS3KeyPrefixInformation(httpClientOperations.execute(client, request)); } LOGGER.info("Successfully retrieved S3 key prefix from the registration server."); LOGGER.info(" S3 key prefix: " + s3KeyPrefixInformation.getS3KeyPrefix()); return s3KeyPrefixInformation; }
From source file:org.finra.herd.tools.retention.destroyer.RetentionExpirationDestroyerWebClient.java
/** * Retrieves business object definition from the herd registration server. * * @param businessObjectDataKey the name of the business object data key * * @return the business object definition * @throws IOException if an I/O error was encountered * @throws JAXBException if a JAXB error was encountered * @throws URISyntaxException if an URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */// w ww . j a v a 2s . c om public BusinessObjectData destroyBusinessObjectData(BusinessObjectDataKey businessObjectDataKey) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { String uriPath = HERD_APP_REST_URI_PREFIX + "/businessObjectData/destroy" + "/namespaces/" + businessObjectDataKey.getNamespace() + "/businessObjectDefinitionNames/" + businessObjectDataKey.getBusinessObjectDefinitionName() + "/businessObjectFormatUsages/" + businessObjectDataKey.getBusinessObjectFormatUsage() + "/businessObjectFormatFileTypes/" + businessObjectDataKey.getBusinessObjectFormatFileType() + "/businessObjectFormatVersions/" + businessObjectDataKey.getBusinessObjectFormatVersion() + "/partitionValues/" + businessObjectDataKey.getPartitionValue() + "/businessObjectDataVersions/" + businessObjectDataKey.getBusinessObjectDataVersion(); URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()) .setHost(regServerAccessParamsDto.getRegServerHost()) .setPort(regServerAccessParamsDto.getRegServerPort()).setPath(uriPath); if (CollectionUtils.isNotEmpty(businessObjectDataKey.getSubPartitionValues())) { uriBuilder.setParameter("subPartitionValues", herdStringHelper.join(businessObjectDataKey.getSubPartitionValues(), "|", "\\")); } URI uri = uriBuilder.build(); try (CloseableHttpClient client = httpClientHelper.createHttpClient( regServerAccessParamsDto.isTrustSelfSignedCertificate(), regServerAccessParamsDto.isDisableHostnameVerification())) { HttpPost request = new HttpPost(uri); request.addHeader("Content-Type", DEFAULT_CONTENT_TYPE); request.addHeader("Accepts", DEFAULT_ACCEPT); // If SSL is enabled, set the client authentication header. if (regServerAccessParamsDto.isUseSsl()) { request.addHeader(getAuthorizationHeader()); } LOGGER.info(String.format(" HTTP POST URI: %s", request.getURI().toString())); LOGGER.info(String.format(" HTTP POST Headers: %s", Arrays.toString(request.getAllHeaders()))); BusinessObjectData businessObjectData = destroyBusinessObjectData( httpClientOperations.execute(client, request)); LOGGER.info("Successfully destroyed business object data from the registration server."); return businessObjectData; } }