Search in sources :

Example 1 with VerifyResult

use of io.cdap.cdap.app.verification.VerifyResult in project cdap by caskdata.

the class ApplicationVerificationTest method testGoodApplication.

/**
 * Good test
 */
@Test
public void testGoodApplication() {
    ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create();
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    ApplicationVerification app = new ApplicationVerification();
    VerifyResult result = app.verify(new ApplicationId("test", newSpec.getName()), newSpec);
    Assert.assertSame(result.getMessage(), result.getStatus(), VerifyResult.Status.SUCCESS);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) AllProgramsApp(io.cdap.cdap.AllProgramsApp) VerifyResult(io.cdap.cdap.app.verification.VerifyResult) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 2 with VerifyResult

use of io.cdap.cdap.app.verification.VerifyResult in project cdap by caskdata.

the class ApplicationVerificationStage method verifyData.

private void verifyData(ApplicationId appId, ApplicationSpecification specification, @Nullable KerberosPrincipalId ownerPrincipal) throws Exception {
    // 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();
        final DatasetId datasetInstanceId = appId.getParent().dataset(dsName);
        // get the authorizing user
        String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, appId, ownerPrincipal);
        DatasetSpecification existingSpec = AuthorizationUtil.authorizeAs(authorizingUser, new Callable<DatasetSpecification>() {

            @Override
            public DatasetSpecification call() throws Exception {
                return 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, ownerPrincipal);
        }
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) VerifyResult(io.cdap.cdap.app.verification.VerifyResult) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) DataSetException(io.cdap.cdap.api.dataset.DataSetException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Example 3 with VerifyResult

use of io.cdap.cdap.app.verification.VerifyResult in project cdap by caskdata.

the class ApplicationVerificationStage method verifyPrograms.

protected void verifyPrograms(ApplicationId appId, ApplicationSpecification specification) {
    Iterable<ProgramSpecification> programSpecs = Iterables.concat(specification.getMapReduce().values(), specification.getWorkflows().values());
    VerifyResult result;
    for (ProgramSpecification programSpec : programSpecs) {
        Verifier<ProgramSpecification> verifier = getVerifier(programSpec.getClass());
        result = verifier.verify(appId, programSpec);
        if (!result.isSuccess()) {
            throw new RuntimeException(result.getMessage());
        }
    }
    for (Map.Entry<String, WorkflowSpecification> entry : specification.getWorkflows().entrySet()) {
        verifyWorkflowSpecifications(specification, entry.getValue());
    }
    for (Map.Entry<String, ScheduleCreationSpec> entry : specification.getProgramSchedules().entrySet()) {
        String programName = entry.getValue().getProgramName();
        if (!specification.getWorkflows().containsKey(programName)) {
            throw new RuntimeException(String.format("Schedule '%s' is invalid: Workflow '%s' is not configured " + "in application '%s'", entry.getValue().getName(), programName, specification.getName()));
        }
    }
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) VerifyResult(io.cdap.cdap.app.verification.VerifyResult) ScheduleCreationSpec(io.cdap.cdap.internal.schedule.ScheduleCreationSpec) Map(java.util.Map)

Example 4 with VerifyResult

use of io.cdap.cdap.app.verification.VerifyResult in project cdap by caskdata.

the class ApplicationVerification method verify.

/**
 * Verifies {@link ApplicationSpecification} being provide.
 *
 * @param input to be verified
 * @return An instance of {@link VerifyResult} depending of status of verification.
 */
@Override
public VerifyResult verify(ApplicationId appId, final ApplicationSpecification input) {
    VerifyResult verifyResult = super.verify(appId, input);
    if (!verifyResult.isSuccess()) {
        return verifyResult;
    }
    // Check if there is at least one program
    // Loop through all program types. For each program type, get the number of programs of that type.
    // Then sum up total number of programs.
    int numberOfPrograms = Arrays.stream(ProgramType.values()).mapToInt(t -> input.getProgramsByType(t).size()).reduce(0, (l, r) -> l + r);
    if (numberOfPrograms <= 0) {
        return VerifyResult.failure(Err.Application.ATLEAST_ONE_PROCESSOR, input.getName());
    }
    return VerifyResult.success();
}
Also used : Arrays(java.util.Arrays) AbstractVerifier(io.cdap.cdap.app.verification.AbstractVerifier) Err(io.cdap.cdap.error.Err) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramType(io.cdap.cdap.api.app.ProgramType) VerifyResult(io.cdap.cdap.app.verification.VerifyResult) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) VerifyResult(io.cdap.cdap.app.verification.VerifyResult)

Aggregations

VerifyResult (io.cdap.cdap.app.verification.VerifyResult)4 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)2 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)2 AllProgramsApp (io.cdap.cdap.AllProgramsApp)1 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)1 ProgramType (io.cdap.cdap.api.app.ProgramType)1 DataSetException (io.cdap.cdap.api.dataset.DataSetException)1 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)1 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)1 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)1 AbstractVerifier (io.cdap.cdap.app.verification.AbstractVerifier)1 Err (io.cdap.cdap.error.Err)1 ApplicationSpecificationAdapter (io.cdap.cdap.internal.app.ApplicationSpecificationAdapter)1 DatasetCreationSpec (io.cdap.cdap.internal.dataset.DatasetCreationSpec)1 ScheduleCreationSpec (io.cdap.cdap.internal.schedule.ScheduleCreationSpec)1 DatasetId (io.cdap.cdap.proto.id.DatasetId)1 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1