@Override public Set<String> getProgramsByType(ProgramType programType) { return delegate.getProgramsByType(programType); } }
/** * Gets all programIds which are defined in the appSpec which are allowed to use profiles. */ private Set<ProgramId> getAllProfileAllowedPrograms(ApplicationSpecification appSpec, ApplicationId appId) { Set<ProgramId> programIds = new HashSet<>(); for (ProgramType programType : PROFILE_ALLOWED_PROGRAM_TYPES) { for (String name : appSpec.getProgramsByType(programType.getApiProgramType())) { programIds.add(appId.program(programType, name)); } } return programIds; } }
/** * 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(); }
/** * Good pipeline with good tests. */ @Test public void testGoodPipeline() throws Exception { Location deployedJar = AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class); ArtifactId artifactId = new ArtifactId("app", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar); AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, AllProgramsApp.class.getName(), null, null, null); ApplicationWithPrograms input = AppFabricTestHelper.getLocalManager().deploy(info).get(); ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp()); // Validate that all programs are being captured by the deployment pipeline Map<ProgramType, Set<String>> programByTypes = new HashMap<>(); for (ProgramDescriptor desc : input.getPrograms()) { ProgramId programId = desc.getProgramId(); programByTypes.computeIfAbsent(programId.getType(), k -> new HashSet<>()).add(programId.getProgram()); } for (co.cask.cdap.api.app.ProgramType programType : co.cask.cdap.api.app.ProgramType.values()) { Assert.assertEquals(appSpec.getProgramsByType(programType), programByTypes.getOrDefault(ProgramType.valueOf(programType.name()), Collections.emptySet())); } }
for (String programName : spec.getProgramsByType(programType)) { co.cask.cdap.proto.ProgramType internalProgramType = co.cask.cdap.proto.ProgramType.valueOf(programType.name()); expectedMetadataChangeEntities.add(appId.program(internalProgramType, programName));
.mapToInt(type -> spec.getProgramsByType(type).size()) .reduce(0, (l, r) -> l + r); Assert.assertEquals(totalPrograms, programs.size()); String type = obj.get("type").getAsString().toUpperCase(); co.cask.cdap.api.app.ProgramType programType = co.cask.cdap.api.app.ProgramType.valueOf(type); return spec.getProgramsByType(programType).contains(obj.get("name").getAsString()); }) );
Set<String> programsByType = allProgramSpec.getProgramsByType(type); verifyProgramList(TEST_NAMESPACE1, ProgramType.valueOf(type.name()), programsByType.size()); Set<String> programsByType = allProgramSpec.getProgramsByType(type); verifyProgramList(TEST_NAMESPACE1, AllProgramsApp.NAME, ProgramType.valueOf(type.name()), programsByType.size());
Assert.assertEquals(expectedSpec.getProgramsByType(programType), specification.getProgramsByType(programType));