use of co.cask.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class AbstractProgramRuntimeServiceTest method testScopingRuntimeArguments.
@Test
public void testScopingRuntimeArguments() throws Exception {
Map<ProgramId, Arguments> argumentsMap = new ConcurrentHashMap<>();
ProgramRunnerFactory runnerFactory = createProgramRunnerFactory(argumentsMap);
final Program program = createDummyProgram();
final ProgramRuntimeService runtimeService = new AbstractProgramRuntimeService(CConfiguration.create(), runnerFactory, null) {
@Override
public ProgramLiveInfo getLiveInfo(ProgramId programId) {
return new ProgramLiveInfo(programId, "runtime") {
};
}
@Override
protected Program createProgram(CConfiguration cConf, ProgramRunner programRunner, ProgramDescriptor programDescriptor, ArtifactDetail artifactDetail, File tempDir) throws IOException {
return program;
}
@Override
protected ArtifactDetail getArtifactDetail(ArtifactId artifactId) throws IOException, ArtifactNotFoundException {
co.cask.cdap.api.artifact.ArtifactId id = new co.cask.cdap.api.artifact.ArtifactId("dummy", new ArtifactVersion("1.0"), ArtifactScope.USER);
return new ArtifactDetail(new ArtifactDescriptor(id, Locations.toLocation(TEMP_FOLDER.newFile())), new ArtifactMeta(ArtifactClasses.builder().build()));
}
};
runtimeService.startAndWait();
try {
try {
ProgramDescriptor descriptor = new ProgramDescriptor(program.getId(), null, null);
// Set of scopes to test
String programScope = program.getType().getScope();
String clusterName = "c1";
List<String> scopes = Arrays.asList("cluster.*.", "cluster." + clusterName + ".", "cluster." + clusterName + ".app.*.", "app.*.", "app." + program.getApplicationId() + ".", "app." + program.getApplicationId() + "." + programScope + ".*.", "app." + program.getApplicationId() + "." + programScope + "." + program.getName() + ".", programScope + ".*.", programScope + "." + program.getName() + ".", "");
for (String scope : scopes) {
ProgramOptions programOptions = new SimpleProgramOptions(program.getName(), new BasicArguments(Collections.singletonMap(Constants.CLUSTER_NAME, clusterName)), new BasicArguments(Collections.singletonMap(scope + "size", Integer.toString(scope.length()))));
final ProgramController controller = runtimeService.run(descriptor, programOptions).getController();
Tasks.waitFor(ProgramController.State.COMPLETED, new Callable<ProgramController.State>() {
@Override
public ProgramController.State call() throws Exception {
return controller.getState();
}
}, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Should get an argument
Arguments args = argumentsMap.get(program.getId());
Assert.assertNotNull(args);
Assert.assertEquals(scope.length(), Integer.parseInt(args.getOption("size")));
}
} finally {
runtimeService.stopAndWait();
}
} finally {
runtimeService.stopAndWait();
}
}
use of co.cask.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 co.cask.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactClient method deleteProperty.
/**
* Delete a property for an artifact. If the property does not exist, this will be a no-op.
*
* @param artifactId the artifact to delete a property from
* @param key the property to delete
* @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 deleteProperty(ArtifactId artifactId, String key) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties/%s", artifactId.getArtifact(), artifactId.getVersion(), key);
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 co.cask.cdap.common.ArtifactNotFoundException in project cdap by caskdata.
the class ArtifactClient method getPluginSummaries.
/**
* Gets all the plugins of the given type available to the given artifact.
*
* @param artifactId the id of the artifact to get
* @param pluginType the type of plugins to get
* @param scope the scope of the artifact
* @return list of {@link PluginSummary}
* @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<PluginSummary> getPluginSummaries(ArtifactId artifactId, String pluginType, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/extensions/%s?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), pluginType, 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<PluginSummary>>fromJsonBody(response, PLUGIN_SUMMARIES_TYPE).getResponseObject();
}
use of co.cask.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();
}
Aggregations