use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.
the class RestIntegrationTest method testCustomProcessorInfos.
@Test
@Ignore
public void testCustomProcessorInfos() throws Exception {
// Some issue with sending multi part for requests using this client and hence this test case is ignored for now. Fix later.
String response;
String prefixUrl = rootUrl + "streams/componentbundles/PROCESSOR/custom";
CustomProcessorInfo customProcessorInfo = createCustomProcessorInfo();
String prefixQueryParam = "?streamingEngine=STORM";
List<String> getUrlQueryParms = new ArrayList<String>();
getUrlQueryParms.add(prefixQueryParam + "&name=ConsoleCustomProcessor");
getUrlQueryParms.add(prefixQueryParam + "&jarFileName=streamline-core.jar");
getUrlQueryParms.add(prefixQueryParam + "&customProcessorImpl=" + ConsoleCustomProcessor.class.getCanonicalName());
List<List<CustomProcessorInfo>> getResults = new ArrayList<List<CustomProcessorInfo>>();
getResults.add(Arrays.asList(customProcessorInfo));
getResults.add(Arrays.asList(customProcessorInfo));
getResults.add(Arrays.asList(customProcessorInfo));
getResults.add(Arrays.asList(customProcessorInfo));
List<String> getUrls = new ArrayList<String>();
for (String queryParam : getUrlQueryParms) {
getUrls.add(prefixUrl + queryParam);
}
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(MultiPartWriter.class);
Client client = ClientBuilder.newClient(clientConfig);
for (String getUrl : getUrls) {
try {
client.target(getUrl).request().get(String.class);
Assert.fail("Should have thrown NotFoundException.");
} catch (NotFoundException e) {
// pass
}
}
/*FileDataBodyPart imageFileBodyPart = new FileDataBodyPart(TopologyCatalogResource.IMAGE_FILE_PARAM_NAME, getCpImageFile(), MediaType
.APPLICATION_OCTET_STREAM_TYPE);
FileDataBodyPart jarFileBodyPart = new FileDataBodyPart(TopologyCatalogResource.JAR_FILE_PARAM_NAME, getCpJarFile(), MediaType
.APPLICATION_OCTET_STREAM_TYPE);*/
MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE);
multiPart.bodyPart(new StreamDataBodyPart(TopologyComponentBundleResource.JAR_FILE_PARAM_NAME, JAR_FILE_STREAM));
multiPart.bodyPart(new FormDataBodyPart(TopologyComponentBundleResource.CP_INFO_PARAM_NAME, customProcessorInfo, MediaType.APPLICATION_JSON_TYPE));
client.target(prefixUrl).request(MediaType.MULTIPART_FORM_DATA_TYPE).post(Entity.entity(multiPart, multiPart.getMediaType()));
for (int i = 0; i < getUrls.size(); ++i) {
String getUrl = getUrls.get(i);
List<CustomProcessorInfo> expectedResults = getResults.get(i);
response = client.target(getUrl).request().get(String.class);
Assert.assertEquals(expectedResults, getEntities(response, expectedResults.get(i).getClass()));
}
}
use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.
the class TopologyComponentBundleResource method updateCustomProcessor.
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/componentbundles/{processor}/custom")
@Timed
public Response updateCustomProcessor(@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, FormDataMultiPart form, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) {
throw new CustomProcessorOnlyException();
}
try (InputStream jarFile = this.getFormDataFromMultiPartRequestAs(InputStream.class, form, JAR_FILE_PARAM_NAME)) {
String customProcessorInfoStr = this.getFormDataFromMultiPartRequestAs(String.class, form, CP_INFO_PARAM_NAME);
String missingParam = (jarFile == null ? JAR_FILE_PARAM_NAME : (customProcessorInfoStr == null ? CP_INFO_PARAM_NAME : null));
if (missingParam != null) {
LOG.debug(missingParam + " is missing or invalid while adding/updating custom processor");
throw BadRequestException.missingParameter(missingParam);
}
CustomProcessorInfo customProcessorInfo = new ObjectMapper().readValue(customProcessorInfoStr, CustomProcessorInfo.class);
CustomProcessorInfo updatedCustomProcessor = catalogService.updateCustomProcessorInfoAsBundle(customProcessorInfo, jarFile, true);
return WSUtils.respondEntity(updatedCustomProcessor, OK);
}
}
use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.
the class TopologyComponentBundleResource method removeCustomProcessorInfo.
@DELETE
@Path("/componentbundles/{processor}/custom/{name}")
@Timed
public Response removeCustomProcessorInfo(@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("name") String name, @Context SecurityContext securityContext) throws IOException {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) {
throw new CustomProcessorOnlyException();
}
CustomProcessorInfo removedCustomProcessorInfo = catalogService.removeCustomProcessorInfoAsBundle(name);
if (removedCustomProcessorInfo != null) {
return WSUtils.respondEntity(removedCustomProcessorInfo, OK);
}
throw EntityNotFoundException.byName(name);
}
use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.
the class CustomProcessorUploadHandlerTest method setup.
@Before
public void setup() throws IOException {
File f = new File(uploadWatchDirectory);
f.mkdir();
f = new File(failedUploadMoveDirectory);
f.mkdir();
f = new File(successfulUploadMoveDirectory);
f.mkdir();
jarFile = new FileInputStream(new File(classLoader.getResource(resourceDirectoryPrefix + "streamline-core.jar").getFile()));
byte[] data = new byte[1024];
ObjectMapper mapper = new ObjectMapper();
FileInputStream fileInputStream = new FileInputStream(new File(classLoader.getResource(resourceDirectoryPrefix + "info.json").getFile()));
fileInputStream.read(data);
fileInputStream.close();
customProcessorInfo = mapper.readValue(data, CustomProcessorInfo.class);
this.customProcessorUploadHandler = new CustomProcessorUploadHandler(uploadWatchDirectory, failedUploadMoveDirectory, successfulUploadMoveDirectory, catalogService);
}
use of com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo in project streamline by hortonworks.
the class CustomProcessorUploadHandlerTest method testSuccessfulUpload.
@Test
public void testSuccessfulUpload() throws IOException, ComponentConfigException, NoSuchAlgorithmException {
String fileName = "consolecustomprocessor.tar";
URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
String consoleCustomProcessorTarString = url.getFile();
File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
new VerificationsInOrder() {
{
InputStream jarFileActual;
CustomProcessorInfo actual;
catalogService.addCustomProcessorInfoAsBundle(actual = withCapture(), jarFileActual = withCapture());
times = 1;
Assert.assertTrue(actual.getName().equals(customProcessorInfo.getName()));
Assert.assertTrue(IOUtils.contentEquals(jarFileActual, jarFile));
}
};
}
Aggregations