use of io.cdap.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactClient method deleteProperties.
/**
* Delete all properties for an artifact. If no properties exist, this will be a no-op.
*
* @param artifactId the artifact to delete properties from
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the artifact does not exist
* @throws IOException if a network error occurred
*/
public void deleteProperties(ArtifactId artifactId) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties", artifactId.getArtifact(), artifactId.getVersion());
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpRequest.Builder requestBuilder = HttpRequest.delete(url);
HttpRequest request = requestBuilder.build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of io.cdap.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactClient method writeProperties.
/**
* Write properties for an artifact. Any existing properties will be overwritten.
*
* @param artifactId the artifact to add properties to
* @param properties the properties to add
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the artifact does not exist
* @throws IOException if a network error occurred
*/
public void writeProperties(ArtifactId artifactId, Map<String, String> properties) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties", artifactId.getArtifact(), artifactId.getVersion());
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpRequest.Builder requestBuilder = HttpRequest.put(url);
HttpRequest request = requestBuilder.withBody(GSON.toJson(properties)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of io.cdap.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactClient method getArtifactInfo.
/**
* Gets information about a specific artifact version.
*
* @param artifactId the id of the artifact to get
* @param scope the scope of the artifact
* @return information about the given artifact
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the given artifact does not exist
*/
public ArtifactInfo getArtifactInfo(ArtifactId artifactId, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), scope.name());
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
}
return ObjectResponse.fromJsonBody(response, ArtifactInfo.class, GSON).getResponseObject();
}
use of io.cdap.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactClient method getPluginTypes.
/**
* Gets all the plugin types available to a specific artifact.
*
* @param artifactId the id of the artifact to get
* @param scope the scope of the artifact
* @return list of plugin types available to the given artifact.
* @throws ArtifactNotFoundException if the given artifact does not exist
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<String> getPluginTypes(ArtifactId artifactId, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/extensions?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), scope.name());
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
}
return ObjectResponse.<List<String>>fromJsonBody(response, EXTENSIONS_TYPE).getResponseObject();
}
use of io.cdap.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactStoreTest method testDelete.
@Test
public void testDelete() throws Exception {
// write an artifact with an app
Id.Artifact parentId = Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.0.0");
ApplicationClass appClass = new ApplicationClass(InspectionApp.class.getName(), "", new ReflectionSchemaGenerator().generate(InspectionApp.AConfig.class));
ArtifactMeta artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addApp(appClass).build());
writeArtifact(parentId, artifactMeta, "parent contents");
// write a child artifact that extends the parent with some plugins
Id.Artifact childId = Id.Artifact.from(Id.Namespace.DEFAULT, "myplugins", "1.0.0");
Id.Artifact anotherId = Id.Artifact.from(Id.Namespace.SYSTEM, "myplugins", "1.0.0");
List<PluginClass> plugins = ImmutableList.of(PluginClass.builder().setName("plugin1").setType("atype").setDescription("").setClassName("c.c.c.plugin1").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build(), PluginClass.builder().setName("plugin2").setType("atype").setDescription("").setClassName("c.c.c.plugin2").setConfigFieldName("cfg").setProperties(ImmutableMap.of()).build());
Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(parentId.getNamespace().getId(), parentId.getName(), new ArtifactVersion("0.1.0"), new ArtifactVersion("2.0.0")));
artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addPlugins(plugins).build(), parents);
writeArtifact(childId, artifactMeta, "child contents");
writeArtifact(anotherId, artifactMeta, "child contents");
// check parent has plugins from the child
Assert.assertFalse(artifactStore.getPluginClasses(NamespaceId.DEFAULT, parentId).isEmpty());
// delete the child artifact
artifactStore.delete(childId);
// check that the other artifact is not getting deleted and the plugin classes are not getting deleted
artifactStore.getArtifact(anotherId);
Assert.assertFalse(artifactStore.getPluginClasses(NamespaceId.SYSTEM, parentId).isEmpty());
// shouldn't be able to get artifact detail
try {
artifactStore.getArtifact(childId);
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
// shouldn't see it in the list
List<ArtifactDetail> artifactList = artifactStore.getArtifacts(parentId.getNamespace().toEntityId());
Assert.assertEquals(1, artifactList.size());
Assert.assertEquals(parentId.getName(), artifactList.get(0).getDescriptor().getArtifactId().getName());
// delete the one in system scope
artifactStore.delete(anotherId);
// shouldn't be able to get artifact detail
try {
artifactStore.getArtifact(anotherId);
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
Assert.assertTrue(artifactStore.getPluginClasses(NamespaceId.SYSTEM, parentId).isEmpty());
// shouldn't see any more plugins for parent
Assert.assertTrue(artifactStore.getPluginClasses(NamespaceId.DEFAULT, parentId).isEmpty());
// delete parent
artifactStore.delete(parentId);
// nothing should be in the list
Assert.assertTrue(artifactStore.getArtifacts(parentId.getNamespace().toEntityId()).isEmpty());
// shouldn't be able to see app class either
Assert.assertTrue(artifactStore.getApplicationClasses(NamespaceId.DEFAULT, appClass.getClassName()).isEmpty());
}
Aggregations