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);
}
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);
}
}
}
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()));
}
}
}
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();
}
Aggregations