/** * Helper static method for creating successfull {@link VerifyResult}. * * @return An instance of {@link VerifyResult} which is successful. */ public static VerifyResult success() { return new VerifyResult(Status.SUCCESS, "OK"); }
private void verifySpec(ApplicationId appId, ApplicationSpecification specification) { VerifyResult result = getVerifier(ApplicationSpecification.class).verify(appId, specification); if (!result.isSuccess()) { throw new RuntimeException(result.getMessage()); } }
/** * 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 of the following : Flow or MapReduce or Workflow for now. // TODO (terence): Logic here is really not good. Need to refactor. if (input.getFlows().isEmpty() && input.getMapReduce().isEmpty() && input.getSpark().isEmpty() && input.getWorkflows().isEmpty() && input.getServices().isEmpty() && input.getWorkers().isEmpty()) { return VerifyResult.failure(Err.Application.ATLEAST_ONE_PROCESSOR, input.getName()); } return VerifyResult.success(); }
/** * Checking if name is an id or no. */ @Test public void testId() throws Exception { AbstractVerifier<String> v = new AbstractVerifier<String>() { @Override protected String getName(String input) { return input; } }; ApplicationId appId = new ApplicationId("test", "some"); Assert.assertTrue(v.verify(appId, "foo").isSuccess()); Assert.assertTrue(v.verify(appId, "mydataset").isSuccess()); Assert.assertFalse(v.verify(appId, "foo name").isSuccess()); Assert.assertTrue(v.verify(appId, "foo-name").isSuccess()); Assert.assertTrue(v.verify(appId, "foo_name").isSuccess()); Assert.assertTrue(v.verify(appId, "foo1234").isSuccess()); Assert.assertFalse(v.verify(appId, "foo^ name").isSuccess()); Assert.assertFalse(v.verify(appId, "foo^name").isSuccess()); Assert.assertFalse(v.verify(appId, "foo/name").isSuccess()); Assert.assertFalse(v.verify(appId, "foo$name").isSuccess()); }
public VerifyResult verify(ApplicationId appId, final FlowSpecification input) { VerifyResult verifyResult = super.verify(appId, input); if (!verifyResult.isSuccess()) { return verifyResult; return VerifyResult.failure(Err.Flow.ATLEAST_ONE_FLOWLET, flowName); return VerifyResult.failure(Err.Flow.ATLEAST_ONE_CONNECTION, flowName); return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName); return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName + ":" + dataSet); return VerifyResult.failure(Err.Flow.OUTPUT_NOT_CONNECTED, flowName, flowletName); return VerifyResult.failure(Err.Flow.NO_INPUT_FOR_OUTPUT, flowName, connection.getTargetName(), connection.getSourceType(), connection.getSourceName()); return VerifyResult.failure(Err.Flow.MORE_OUTPUT_NOT_ALLOWED, flowName, node.getType().toString().toLowerCase(), node.getName(), outputs); return VerifyResult.success();
/** * 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); }
private void verifySpec(ApplicationId appId, ApplicationSpecification specification) { VerifyResult result = getVerifier(ApplicationSpecification.class).verify(appId, specification); if (!result.isSuccess()) { throw new RuntimeException(result.getMessage()); } }
/** * 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(); }
/** * Helper static method for creating successfull {@link VerifyResult}. * * @return An instance of {@link VerifyResult} which is successful. */ public static VerifyResult success() { return new VerifyResult(Status.SUCCESS, "OK"); }
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())); } } }
/** * Helper static method for creating failure {@link VerifyResult} with * a descriptive message. * * @return An instance of {@link VerifyResult} which has failed with descriptive message. */ public static VerifyResult failure(Errors error, Object... objects) { return new VerifyResult(Status.FAILED, error.getMessage(objects)); } }
protected void verifyPrograms(ApplicationId appId, ApplicationSpecification specification) { Iterable<ProgramSpecification> programSpecs = Iterables.concat(specification.getFlows().values(), specification.getMapReduce().values(), specification.getWorkflows().values()); VerifyResult result; for (ProgramSpecification programSpec : programSpecs) { result = getVerifier(programSpec.getClass()).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())); } } }
/** * Helper static method for creating failure {@link VerifyResult} with * a descriptive message. * * @return An instance of {@link VerifyResult} which has failed with descriptive message. */ public static VerifyResult failure(Errors error, Object... objects) { return new VerifyResult(Status.FAILED, error.getMessage(objects)); } }
result = getVerifier(DatasetCreationSpec.class).verify(appId, dataSetCreateSpec); if (!result.isSuccess()) { throw new RuntimeException(result.getMessage());
result = getVerifier(DatasetCreationSpec.class).verify(appId, dataSetCreateSpec); if (!result.isSuccess()) { throw new RuntimeException(result.getMessage()); result = getVerifier(StreamSpecification.class).verify(appId, spec); if (!result.isSuccess()) { throw new RuntimeException(result.getMessage());