Search in sources :

Example 6 with VerifyResult

use of co.cask.cdap.app.verification.VerifyResult in project cdap by caskdata.

the class ApplicationVerificationStage method verifyData.

protected void verifyData(ApplicationId appId, ApplicationSpecification specification, @Nullable KerberosPrincipalId specifiedOwnerPrincipal) throws DatasetManagementException, UnauthorizedException {
    // NOTE: no special restrictions on dataset module names, etc
    VerifyResult result;
    for (DatasetCreationSpec dataSetCreateSpec : specification.getDatasets().values()) {
        result = getVerifier(DatasetCreationSpec.class).verify(appId, dataSetCreateSpec);
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getMessage());
        }
        String dsName = dataSetCreateSpec.getInstanceName();
        DatasetId datasetInstanceId = appId.getParent().dataset(dsName);
        DatasetSpecification existingSpec = dsFramework.getDatasetSpec(datasetInstanceId);
        if (existingSpec != null && !existingSpec.getType().equals(dataSetCreateSpec.getTypeName())) {
            // New app trying to deploy an dataset with same instanceName but different Type than that of existing.
            throw new DataSetException(String.format("Cannot Deploy Dataset : %s with Type : %s : Dataset with different Type Already Exists", dsName, dataSetCreateSpec.getTypeName()));
        }
        // if the dataset existed verify its owner is same.
        if (existingSpec != null) {
            verifyOwner(datasetInstanceId, specifiedOwnerPrincipal);
        }
    }
    for (StreamSpecification spec : specification.getStreams().values()) {
        result = getVerifier(StreamSpecification.class).verify(appId, spec);
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getMessage());
        }
        // if the stream existed verify the owner to be the same
        if (store.getStream(appId.getNamespaceId(), spec.getName()) != null) {
            verifyOwner(appId.getParent().stream(spec.getName()), specifiedOwnerPrincipal);
        }
    }
}
Also used : DataSetException(co.cask.cdap.api.dataset.DataSetException) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) VerifyResult(co.cask.cdap.app.verification.VerifyResult) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 7 with VerifyResult

use of co.cask.cdap.app.verification.VerifyResult in project cdap by caskdata.

the class FlowVerificationTest method testValidFlow.

@Test
public void testValidFlow() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowSpec = new FlowVerification();
    for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
        VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
        Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WebCrawlApp(co.cask.cdap.WebCrawlApp) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Map(java.util.Map) Test(org.junit.Test)

Aggregations

VerifyResult (co.cask.cdap.app.verification.VerifyResult)7 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)4 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)4 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 Map (java.util.Map)4 Test (org.junit.Test)4 WebCrawlApp (co.cask.cdap.WebCrawlApp)3 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)3 ProgramSpecification (co.cask.cdap.api.ProgramSpecification)1 Schema (co.cask.cdap.api.data.schema.Schema)1 StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)1 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)1 FlowletConnection (co.cask.cdap.api.flow.FlowletConnection)1 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1 QueueSpecification (co.cask.cdap.app.queue.QueueSpecification)1 QueueSpecificationGenerator (co.cask.cdap.app.queue.QueueSpecificationGenerator)1 SimpleQueueSpecificationGenerator (co.cask.cdap.internal.app.queue.SimpleQueueSpecificationGenerator)1