use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class RemoteExecutionJobMain method initialize.
@VisibleForTesting
RemoteExecutionRuntimeJobEnvironment initialize(CConfiguration cConf) throws Exception {
zkServer = InMemoryZKServer.builder().build();
zkServer.startAndWait();
InetSocketAddress zkAddr = ResolvingDiscoverable.resolve(zkServer.getLocalAddress());
String zkConnectStr = String.format("%s:%d", zkAddr.getHostString(), zkAddr.getPort());
LOG.debug("In memory ZK started at {}", zkConnectStr);
cConf.set(Constants.Zookeeper.QUORUM, zkConnectStr);
Injector injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getDefaultModule(), new DFSLocationModule(), new InMemoryDiscoveryModule(), new TwillModule(), new AuthenticationContextModules().getProgramContainerModule(cConf), new AbstractModule() {
@Override
protected void configure() {
// don't need to perform any impersonation from within user programs
bind(UGIProvider.class).to(CurrentUGIProvider.class).in(Scopes.SINGLETON);
// Binds a no-op SecureStore for the TwillModule to setup TokenSecureStoreRenewer.
bind(SecureStore.class).toInstance(new SecureStore() {
@Override
public List<SecureStoreMetadata> list(String namespace) {
return Collections.emptyList();
}
@Override
public SecureStoreData get(String namespace, String name) throws Exception {
throw new NotFoundException("Secure key " + name + " not found in namespace " + namespace);
}
});
}
});
Map<String, String> properties = new HashMap<>();
properties.put(Constants.Zookeeper.QUORUM, zkConnectStr);
locationFactory = injector.getInstance(LocationFactory.class);
locationFactory.create("/").mkdirs();
twillRunnerService = injector.getInstance(TwillRunnerService.class);
twillRunnerService.start();
if (UserGroupInformation.isSecurityEnabled()) {
TokenSecureStoreRenewer secureStoreRenewer = injector.getInstance(TokenSecureStoreRenewer.class);
secureStoreUpdateCancellable = twillRunnerService.setSecureStoreRenewer(secureStoreRenewer, 30000L, secureStoreRenewer.getUpdateInterval(), 30000L, TimeUnit.MILLISECONDS);
}
return new RemoteExecutionRuntimeJobEnvironment(locationFactory, twillRunnerService, properties);
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class SystemProfileCreatorTest method testCreation.
@Test
public void testCreation() throws Exception {
ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
try {
profileService.getProfile(profileId);
Assert.fail("profile should not exist.");
} catch (NotFoundException e) {
// expected
}
List<ProvisionerPropertyValue> properties = new ArrayList<>();
properties.add(new ProvisionerPropertyValue("name1", "val1", true));
properties.add(new ProvisionerPropertyValue("name2", "val2", true));
ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties);
Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo);
SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getProvisioner());
BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
Assert.assertEquals(expected, result);
Assert.assertEquals(profile, profileService.getProfile(profileId));
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class DefaultStoreTest method testProgramRunCount.
@Test
public void testProgramRunCount() {
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
ArtifactId testArtifact = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
ProgramId workflowId = appId.workflow(AllProgramsApp.NoOpWorkflow.NAME);
ProgramId serviceId = appId.service(AllProgramsApp.NoOpService.NAME);
ProgramId nonExistingAppProgramId = NamespaceId.DEFAULT.app("nonExisting").workflow("test");
ProgramId nonExistingProgramId = appId.workflow("nonExisting");
// add the application
store.addApplication(appId, spec);
// add some run records to workflow and service
for (int i = 0; i < 5; i++) {
setStart(workflowId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
setStart(serviceId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
}
List<RunCountResult> result = store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId, nonExistingAppProgramId, nonExistingProgramId));
// compare the result
Assert.assertEquals(4, result.size());
for (RunCountResult runCountResult : result) {
ProgramId programId = runCountResult.getProgramId();
Long count = runCountResult.getCount();
if (programId.equals(nonExistingAppProgramId) || programId.equals(nonExistingProgramId)) {
Assert.assertNull(count);
Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
} else {
Assert.assertNotNull(count);
Assert.assertEquals(5L, count.longValue());
}
}
// remove the app should remove all run count
store.removeApplication(appId);
for (RunCountResult runCountResult : store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId))) {
Assert.assertNull(runCountResult.getCount());
Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
}
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class MasterEnvironments method create.
/**
* Creates a new instance of {@link MasterEnvironment}.
*
* @param cConf the CDAP configuration
* @param envName the master environment name
* @return a new, initialized instance
* @throws NotFoundException if the master environment of the given name does not exist
*/
public static MasterEnvironment create(CConfiguration cConf, String envName) throws NotFoundException {
MasterEnvironmentExtensionLoader loader = new MasterEnvironmentExtensionLoader(cConf);
MasterEnvironment masterEnv = loader.get(envName);
if (masterEnv == null) {
throw new NotFoundException("Master environment of name " + envName + " does not exist");
}
return masterEnv;
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramClient method getWorkerInstances.
/**
* Gets the number of instances that a worker is currently running on.
*
* @param worker the worker
* @return number of instances that the worker is currently running on
* @throws IOException if a network error occurred
* @throws NotFoundException if the application or worker could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public int getWorkerInstances(ProgramId worker) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(worker.getNamespaceId(), String.format("apps/%s/workers/%s/instances", worker.getApplication(), worker.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(worker);
}
return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
}
Aggregations