use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DatasetTypeHandlerTest method testNotFound.
@Test
public void testNotFound() throws Exception {
NamespaceId nonExistent = new NamespaceId("nonExistent");
HttpResponse response = makeModulesRequest(nonExistent);
assertNamespaceNotFound(response, nonExistent);
response = makeTypesRequest(nonExistent);
assertNamespaceNotFound(response, nonExistent);
DatasetModuleId datasetModule = nonExistent.datasetModule("module");
response = makeModuleInfoRequest(datasetModule);
assertNamespaceNotFound(response, nonExistent);
DatasetTypeId datasetType = nonExistent.datasetType("type");
response = makeTypeInfoRequest(datasetType);
assertNamespaceNotFound(response, nonExistent);
response = deployModule(datasetModule, TestModule1.class);
assertNamespaceNotFound(response, nonExistent);
response = deleteModule(datasetModule);
assertNamespaceNotFound(response, nonExistent);
response = deleteModules(nonExistent);
assertNamespaceNotFound(response, nonExistent);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class DatasetInstanceHandlerTest method testNotFound.
@Test
public void testNotFound() throws IOException {
NamespaceId nonExistent = new NamespaceId("nonexistent");
DatasetId datasetInstance = nonExistent.dataset("ds");
HttpResponse response = makeInstancesRequest(nonExistent.getNamespace());
assertNamespaceNotFound(response, nonExistent);
// TODO: commented out for now until we add back namespace checks on get dataset CDAP-3901
// response = getInstance(datasetInstance);
// assertNamespaceNotFound(response, nonExistent);
response = createInstance(datasetInstance, Table.class.getName(), null);
assertNamespaceNotFound(response, nonExistent);
response = updateInstance(datasetInstance, DatasetProperties.EMPTY);
assertNamespaceNotFound(response, nonExistent);
response = deleteInstance(datasetInstance);
assertNamespaceNotFound(response, nonExistent);
// it should be ok to use system
response = getInstances(NamespaceId.SYSTEM.getNamespace());
Assert.assertEquals(200, response.getResponseCode());
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AppLifecycleHttpHandler method getAllApps.
/**
* Returns a list of applications associated with a namespace.
*/
@GET
@Path("/apps")
public void getAllApps(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("artifactName") String artifactName, @QueryParam("artifactVersion") String artifactVersion, @QueryParam("pageToken") String pageToken, @QueryParam("pageSize") Integer pageSize, @QueryParam("orderBy") SortOrder orderBy, @QueryParam("nameFilter") String nameFilter) throws Exception {
NamespaceId namespace = validateNamespace(namespaceId);
Set<String> names = new HashSet<>();
if (!Strings.isNullOrEmpty(artifactName)) {
for (String name : Splitter.on(',').split(artifactName)) {
names.add(name);
}
}
if (Optional.ofNullable(pageSize).orElse(0) != 0) {
JsonPaginatedListResponder.respond(GSON, responder, APP_LIST_PAGINATED_KEY, jsonListResponder -> {
AtomicReference<ApplicationRecord> lastRecord = new AtomicReference<>(null);
ScanApplicationsRequest scanRequest = getScanRequest(namespaceId, artifactVersion, pageToken, pageSize, orderBy, nameFilter, names);
boolean pageLimitReached = applicationLifecycleService.scanApplications(scanRequest, appDetail -> {
ApplicationRecord record = new ApplicationRecord(appDetail);
jsonListResponder.send(record);
lastRecord.set(record);
});
ApplicationRecord record = lastRecord.get();
return !pageLimitReached || record == null ? null : record.getName() + EntityId.IDSTRING_PART_SEPARATOR + record.getAppVersion();
});
} else {
ScanApplicationsRequest scanRequest = getScanRequest(namespaceId, artifactVersion, pageToken, null, orderBy, nameFilter, names);
JsonWholeListResponder.respond(GSON, responder, jsonListResponder -> applicationLifecycleService.scanApplications(scanRequest, d -> jsonListResponder.send(new ApplicationRecord(d))));
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method deleteProperties.
@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties")
public void deleteProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) throws Exception {
NamespaceId namespace = NamespaceId.SYSTEM.getNamespace().equalsIgnoreCase(namespaceId) ? NamespaceId.SYSTEM : validateAndGetNamespace(namespaceId);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
artifactRepository.deleteArtifactProperties(Id.Artifact.fromEntityId(artifactId));
responder.sendStatus(HttpResponseStatus.OK);
} catch (IOException e) {
LOG.error("Exception deleting properties for artifact {}.", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error deleting properties for artifact.");
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifacts.
@GET
@Path("/namespaces/{namespace-id}/artifacts")
public void getArtifacts(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @Nullable @QueryParam("scope") String scope) throws Exception {
try {
if (scope == null) {
NamespaceId namespace = validateAndGetNamespace(namespaceId);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, true)));
} else {
NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, false)));
}
} catch (IOException e) {
LOG.error("Exception reading artifact metadata for namespace {} from the store.", namespaceId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store.");
}
}
Aggregations