use of io.cdap.cdap.proto.id.InstanceId in project cdap by caskdata.
the class EntityExistenceTest method testExists.
@Test
@SuppressWarnings("unchecked")
public void testExists() throws NotFoundException, UnauthorizedException {
existenceVerifier.ensureExists(new InstanceId(EXISTS));
existenceVerifier.ensureExists(NAMESPACE);
existenceVerifier.ensureExists(ARTIFACT);
ApplicationId app = NAMESPACE.app(AllProgramsApp.NAME);
existenceVerifier.ensureExists(app);
existenceVerifier.ensureExists(app.mr(AllProgramsApp.NoOpMR.NAME));
existenceVerifier.ensureExists(NAMESPACE.dataset(AllProgramsApp.DATASET_NAME));
}
use of io.cdap.cdap.proto.id.InstanceId in project cdap by caskdata.
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.InstanceId in project cdap by caskdata.
the class ApplicationLifecycleService method createAppDetailsArchive.
/**
* Creates a ZIP archive that contains the {@link ApplicationDetail} for all applications. The archive created will
* contain a directory entry for each of the namespace. Inside each namespace directory, it contains the
* application detail json, the application name as the file name, with {@code ".json"} as the file extension.
* <p/>
* This method requires instance admin permission.
*
* @param zipOut the {@link ZipOutputStream} for writing out the application details
*/
public void createAppDetailsArchive(ZipOutputStream zipOut) throws Exception {
accessEnforcer.enforce(new InstanceId(cConf.get(Constants.INSTANCE_NAME)), authenticationContext.getPrincipal(), StandardPermission.GET);
Set<NamespaceId> namespaces = new HashSet<>();
JsonWriter jsonWriter = new JsonWriter(new OutputStreamWriter(zipOut, StandardCharsets.UTF_8));
store.scanApplications(batchSize, (appId, appSpec) -> {
// Skip the SYSTEM namespace apps
if (NamespaceId.SYSTEM.equals(appId.getParent())) {
return;
}
try {
ApplicationDetail applicationDetail = enforceApplicationDetailAccess(appId, ApplicationDetail.fromSpec(appSpec, null));
// Add a directory for the namespace
if (namespaces.add(appId.getParent())) {
ZipEntry entry = new ZipEntry(appId.getNamespace() + "/");
zipOut.putNextEntry(entry);
zipOut.closeEntry();
}
ZipEntry entry = new ZipEntry(appId.getNamespace() + "/" + appId.getApplication() + ".json");
zipOut.putNextEntry(entry);
GSON.toJson(applicationDetail, ApplicationDetail.class, jsonWriter);
jsonWriter.flush();
zipOut.closeEntry();
} catch (IOException | AccessException e) {
throw new RuntimeException("Failed to add zip entry for application " + appId, e);
}
});
}
use of io.cdap.cdap.proto.id.InstanceId in project cdap by caskdata.
the class MonitorHandlerAuthorizationTest method testGetServiceSpecAuthorization.
@Test
public void testGetServiceSpecAuthorization() throws Exception {
InstanceId instanceId = InstanceId.SELF;
MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(instanceId, EntityType.SYSTEM_SERVICE), Arrays.asList(StandardPermission.LIST));
HttpRequest request = mock(HttpRequest.class);
HttpResponder responder = mock(HttpResponder.class);
AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
try {
handler.getServiceSpec(request, responder);
} catch (UnauthorizedException e) {
// expected
}
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
handler.getServiceSpec(request, responder);
}
use of io.cdap.cdap.proto.id.InstanceId in project cdap by caskdata.
the class PreferencesHttpHandler method deleteInstancePrefs.
@Path("/preferences")
@DELETE
public void deleteInstancePrefs(HttpRequest request, HttpResponder responder) throws Exception {
InstanceId instanceId = new InstanceId("");
accessEnforcer.enforce(instanceId, authenticationContext.getPrincipal(), StandardPermission.UPDATE);
preferencesService.deleteProperties();
responder.sendStatus(HttpResponseStatus.OK);
}
Aggregations