Search in sources :

Example 1 with CustomProcessorInfo

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()));
    }
}
Also used : StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) NotFoundException(javax.ws.rs.NotFoundException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Ignore(org.junit.Ignore) IntegrationTest(com.hortonworks.streamline.common.test.IntegrationTest) Test(org.junit.Test)

Example 2 with CustomProcessorInfo

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);
    }
}
Also used : InputStream(java.io.InputStream) CustomProcessorOnlyException(com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 3 with CustomProcessorInfo

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);
}
Also used : CustomProcessorOnlyException(com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with CustomProcessorInfo

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);
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) Before(org.junit.Before)

Example 5 with CustomProcessorInfo

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));
        }
    };
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) URL(java.net.URL) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Aggregations

CustomProcessorInfo (com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo)12 InputStream (java.io.InputStream)6 Timed (com.codahale.metrics.annotation.Timed)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CustomProcessorOnlyException (com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException)4 FileInputStream (java.io.FileInputStream)4 Path (javax.ws.rs.Path)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 QueryParam (com.hortonworks.registries.common.QueryParam)2 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 Test (org.junit.Test)2 ComponentConfigException (com.hortonworks.streamline.common.exception.ComponentConfigException)1 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)1 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)1 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)1 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)1 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)1 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)1