Search in sources :

Example 11 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ValidationHandler method validatePipeline.

@POST
@Path("v1/contexts/{context}/validations/pipeline")
public void validatePipeline(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespace) throws IOException {
    if (!getContext().getAdmin().namespaceExists(namespace)) {
        responder.sendError(HttpURLConnection.HTTP_NOT_FOUND, String.format("Namespace '%s' does not exist", namespace));
        return;
    }
    AppRequest<JsonObject> appRequest;
    try {
        appRequest = GSON.fromJson(StandardCharsets.UTF_8.decode(request.getContent()).toString(), APP_REQUEST_TYPE);
        appRequest.validate();
    } catch (JsonSyntaxException e) {
        responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Unable to decode request body: " + e.getMessage());
        return;
    } catch (IllegalArgumentException e) {
        responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Invalid artifact in pipeline request: " + e.getMessage());
        return;
    }
    ArtifactSummary artifactSummary = appRequest.getArtifact();
    if (StudioUtil.isBatchPipeline(artifactSummary)) {
        responder.sendJson(validateBatchPipeline(appRequest));
    } else if (StudioUtil.isStreamingPipeline(artifactSummary)) {
        responder.sendJson(validateStreamingPipeline(appRequest));
    } else {
        responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, String.format("Invalid artifact '%s'. Must be '%s' or '%s'.", artifactSummary.getName(), StudioUtil.ARTIFACT_BATCH_NAME, StudioUtil.ARTIFACT_STREAMING_NAME));
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) JsonObject(com.google.gson.JsonObject) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 12 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class DataPipelineServiceTest method testValidatePipelineChecksNamespaceExistence.

@Test
public void testValidatePipelineChecksNamespaceExistence() throws IOException {
    ETLBatchConfig config = ETLBatchConfig.builder().addStage(new ETLStage("src", MockSource.getPlugin("dummy1"))).addStage(new ETLStage("sink", MockSink.getPlugin("dummy2"))).addConnection("src", "sink").build();
    ArtifactSummary badArtifact = new ArtifactSummary("ghost", "1.0.0");
    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(badArtifact, config);
    URL validatePipelineURL = serviceURI.resolve("v1/contexts/ghost/validations/pipeline").toURL();
    HttpRequest request = HttpRequest.builder(HttpMethod.POST, validatePipelineURL).withBody(GSON.toJson(appRequest)).build();
    HttpResponse response = HttpRequests.execute(request, new DefaultHttpRequestConfig(false));
    Assert.assertEquals(404, response.getResponseCode());
}
Also used : ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) HttpRequest(io.cdap.common.http.HttpRequest) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 13 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class DraftServiceTest method createBatchPipelineDraft.

private Draft createBatchPipelineDraft(DraftId draftId, String name, String description) throws IOException {
    ArtifactSummary artifact = new ArtifactSummary("cdap-data-pipeline", "1.0.0");
    ETLBatchConfig config = ETLBatchConfig.builder().addStage(new ETLStage("src", MockSource.getPlugin("dummy1"))).addStage(new ETLStage("sink", MockSink.getPlugin("dummy2"))).addConnection("src", "sink").setEngine(Engine.SPARK).build();
    DraftStoreRequest<ETLBatchConfig> batchDraftStoreRequest = new DraftStoreRequest<>(config, "", name, description, 0, artifact);
    long now = System.currentTimeMillis();
    Draft expectedDraft = new Draft(config, name, description, artifact, draftId.getId(), now, now);
    createPipelineDraft(draftId, batchDraftStoreRequest);
    return expectedDraft;
}
Also used : ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) DraftStoreRequest(io.cdap.cdap.datapipeline.draft.DraftStoreRequest) Draft(io.cdap.cdap.datapipeline.draft.Draft) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage)

Example 14 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ListArtifactVersionsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
    String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
    List<ArtifactSummary> artifactSummaries;
    if (scopeStr == null) {
        artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName);
    } else {
        ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
        artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName, scope);
    }
    Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {

        @Override
        public List<?> makeRow(ArtifactSummary object) {
            return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker)

Example 15 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ListArtifactsCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<ArtifactSummary> artifactSummaries;
    String artifactScope = arguments.getOptional(ArgumentName.SCOPE.toString());
    if (artifactScope == null) {
        artifactSummaries = artifactClient.list(cliConfig.getCurrentNamespace());
    } else {
        artifactSummaries = artifactClient.list(cliConfig.getCurrentNamespace(), ArtifactScope.valueOf(artifactScope.toUpperCase()));
    }
    Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {

        @Override
        public List<?> makeRow(ArtifactSummary object) {
            return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker)

Aggregations

ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)152 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)86 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)80 Test (org.junit.Test)70 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)48 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)44 ProgramId (io.cdap.cdap.proto.id.ProgramId)44 Id (io.cdap.cdap.common.id.Id)36 ProfileId (io.cdap.cdap.proto.id.ProfileId)26 HttpResponse (io.cdap.common.http.HttpResponse)26 IOException (java.io.IOException)22 URL (java.net.URL)22 JsonObject (com.google.gson.JsonObject)18 NotFoundException (io.cdap.cdap.common.NotFoundException)18 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)16 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)16 File (java.io.File)16 Map (java.util.Map)16 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)14 KerberosPrincipalId (io.cdap.cdap.proto.id.KerberosPrincipalId)14