use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileServiceTest method testAddDeleteAssignments.
@Test
public void testAddDeleteAssignments() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
Profile profile1 = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
profileService.saveProfile(myProfile, profile1);
// add a profile assignment and verify
Set<EntityId> expected = new HashSet<>();
expected.add(NamespaceId.DEFAULT);
profileService.addProfileAssignment(myProfile, NamespaceId.DEFAULT);
Assert.assertEquals(expected, profileService.getProfileAssignments(myProfile));
// add more and verify
InstanceId instanceId = new InstanceId("");
ApplicationId myApp = NamespaceId.DEFAULT.app("myApp");
ProgramId myProgram = myApp.workflow("myProgram");
expected.add(instanceId);
expected.add(myApp);
expected.add(myProgram);
profileService.addProfileAssignment(myProfile, instanceId);
profileService.addProfileAssignment(myProfile, myApp);
profileService.addProfileAssignment(myProfile, myProgram);
Assert.assertEquals(expected, profileService.getProfileAssignments(myProfile));
// add same entity id should not affect
profileService.addProfileAssignment(myProfile, myApp);
Assert.assertEquals(expected, profileService.getProfileAssignments(myProfile));
// delete one and verify
expected.remove(myApp);
profileService.removeProfileAssignment(myProfile, myApp);
Assert.assertEquals(expected, profileService.getProfileAssignments(myProfile));
// delete all
for (EntityId entityId : expected) {
profileService.removeProfileAssignment(myProfile, entityId);
}
expected.clear();
Assert.assertEquals(expected, profileService.getProfileAssignments(myProfile));
// delete again should not affect
profileService.removeProfileAssignment(myProfile, myApp);
Assert.assertEquals(expected, profileService.getProfileAssignments(myProfile));
profileService.disableProfile(myProfile);
profileService.deleteProfile(myProfile);
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileServiceTest method testProfileMetricsDeletion.
@Test
public void testProfileMetricsDeletion() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
ProgramRunId runId = NamespaceId.DEFAULT.app("myApp").workflow("myProgram").run(RunIds.generate());
// create and disable the profile
profileService.saveProfile(myProfile, profile);
profileService.disableProfile(myProfile);
// emit some metrics
MetricsCollectionService metricService = getInjector().getInstance(MetricsCollectionService.class);
MetricsContext metricsContext = metricService.getContext(getMetricsTags(runId, myProfile));
metricsContext.increment(Constants.Metrics.Program.PROGRAM_NODE_MINUTES, 30L);
MetricStore metricStore = getInjector().getInstance(MetricStore.class);
Tasks.waitFor(30L, () -> getMetric(metricStore, runId, myProfile, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
// delete and verify the metrics are gone
profileService.deleteProfile(myProfile);
Tasks.waitFor(0L, () -> getMetric(metricStore, runId, myProfile, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileServiceTest method testProfileDeletion.
@Test
public void testProfileDeletion() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
ProfileId myProfile2 = NamespaceId.DEFAULT.profile("MyProfile2");
Profile profile1 = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
Profile profile2 = new Profile("MyProfile2", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), ProfileStatus.DISABLED, Profile.NATIVE.getProvisioner());
profileService.saveProfile(myProfile, profile1);
// add profile2 and disable it, profile2 can get deleted at any time
profileService.saveProfile(myProfile2, profile2);
profileService.disableProfile(myProfile2);
// Should not be able to delete because the profile is by default enabled
try {
profileService.deleteProfile(myProfile);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
try {
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.fail();
} catch (ProfileConflictException e) {
// expected and check profile 2 is not getting deleted
Assert.assertEquals(profile2, profileService.getProfile(myProfile2));
}
// add assignment and disable it, deletion should also fail
profileService.addProfileAssignment(myProfile, NamespaceId.DEFAULT);
profileService.disableProfile(myProfile);
try {
profileService.deleteProfile(myProfile);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
try {
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.fail();
} catch (ProfileConflictException e) {
// expected and check profile 2 is not getting deleted
Assert.assertEquals(profile2, profileService.getProfile(myProfile2));
}
profileService.removeProfileAssignment(myProfile, NamespaceId.DEFAULT);
// add an active record to DefaultStore, deletion should still fail
Store store = getDefaultStore();
ProgramId programId = NamespaceId.DEFAULT.app("myApp").workflow("myProgram");
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
RunId runId = RunIds.generate(System.currentTimeMillis());
ProgramRunId programRunId = programId.run(runId.getId());
Map<String, String> systemArgs = Collections.singletonMap(SystemArguments.PROFILE_NAME, myProfile.getScopedName());
int sourceId = 0;
store.setProvisioning(programRunId, Collections.emptyMap(), systemArgs, AppFabricTestHelper.createSourceId(++sourceId), artifactId);
store.setProvisioned(programRunId, 0, AppFabricTestHelper.createSourceId(++sourceId));
store.setStart(programRunId, null, systemArgs, AppFabricTestHelper.createSourceId(++sourceId));
try {
profileService.deleteProfile(myProfile);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
try {
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.fail();
} catch (ProfileConflictException e) {
// expected and check profile 2 is not getting deleted
Assert.assertEquals(profile2, profileService.getProfile(myProfile2));
}
// set the run to stopped then deletion should work
store.setStop(programRunId, System.currentTimeMillis() + 1000, ProgramController.State.ERROR.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
// now profile deletion should succeed
profileService.deleteProfile(myProfile);
Assert.assertEquals(Collections.singletonList(profile2), profileService.getProfiles(NamespaceId.DEFAULT, false));
profileService.saveProfile(myProfile, profile1);
profileService.disableProfile(myProfile);
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.assertEquals(Collections.emptyList(), profileService.getProfiles(NamespaceId.DEFAULT, false));
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileMetadataMessageProcessor method collectProgramProfileMetadata.
private void collectProgramProfileMetadata(ProgramId programId, @Nullable ProfileId appProfile, List<MetadataMutation> updates) throws IOException {
ProfileId programProfile = appProfile == null ? getResolvedProfileId(programId) : getProfileId(programId).orElse(appProfile);
addProfileMetadataUpdate(programId, programProfile, updates);
for (ProgramSchedule schedule : scheduleDataset.listSchedules(programId)) {
collectScheduleProfileMetadata(schedule, programProfile, updates);
}
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProgramNotificationSubscriberServiceTest method testMetricsEmit.
@Test
public void testMetricsEmit() throws Exception {
ProfileService profileService = injector.getInstance(ProfileService.class);
// create my profile
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
profileService.saveProfile(myProfile, Profile.NATIVE);
ProgramId programId = NamespaceId.DEFAULT.app("myApp").workflow("myProgram");
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
RunId runId = RunIds.generate(System.currentTimeMillis());
ProgramRunId programRunId = programId.run(runId.getId());
Map<String, String> systemArgs = Collections.singletonMap(SystemArguments.PROFILE_NAME, myProfile.getScopedName());
long startTime = System.currentTimeMillis();
// record the program status in app meta store
TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
int sourceId = 0;
metadataStoreDataset.recordProgramProvisioning(programRunId, Collections.emptyMap(), systemArgs, AppFabricTestHelper.createSourceId(++sourceId), artifactId);
// using 3 nodes
metadataStoreDataset.recordProgramProvisioned(programRunId, 3, AppFabricTestHelper.createSourceId(++sourceId));
metadataStoreDataset.recordProgramStart(programRunId, null, systemArgs, AppFabricTestHelper.createSourceId(++sourceId));
metadataStoreDataset.recordProgramRunning(programRunId, startTime + 60000, null, AppFabricTestHelper.createSourceId(++sourceId));
});
programStateWriter.completed(programRunId);
MetricStore metricStore = injector.getInstance(MetricStore.class);
Map<String, String> additionalTags = getAdditionalTagsForProgramMetrics(ProgramRunStatus.RUNNING, null, ProgramRunClusterStatus.PROVISIONED);
Tasks.waitFor(1L, () -> getMetric(metricStore, programRunId, myProfile, additionalTags, SYSTEM_METRIC_PREFIX + Constants.Metrics.Program.PROGRAM_COMPLETED_RUNS), 10, TimeUnit.SECONDS);
// verify the metrics
Assert.assertEquals(1L, getMetric(metricStore, programRunId, myProfile, additionalTags, SYSTEM_METRIC_PREFIX + Constants.Metrics.Program.PROGRAM_COMPLETED_RUNS));
Assert.assertEquals(0L, getMetric(metricStore, programRunId, myProfile, additionalTags, SYSTEM_METRIC_PREFIX + Constants.Metrics.Program.PROGRAM_KILLED_RUNS));
Assert.assertEquals(0L, getMetric(metricStore, programRunId, myProfile, additionalTags, SYSTEM_METRIC_PREFIX + Constants.Metrics.Program.PROGRAM_FAILED_RUNS));
metricStore.deleteAll();
}
Aggregations