Search in sources :

Example 1 with NotFoundException

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);
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) TwillModule(io.cdap.cdap.app.guice.TwillModule) SecureStoreMetadata(io.cdap.cdap.api.security.store.SecureStoreMetadata) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) TokenSecureStoreRenewer(io.cdap.cdap.security.TokenSecureStoreRenewer) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) NotFoundException(io.cdap.cdap.common.NotFoundException) SecureStore(io.cdap.cdap.api.security.store.SecureStore) AbstractModule(com.google.inject.AbstractModule) LocationFactory(org.apache.twill.filesystem.LocationFactory) DFSLocationModule(io.cdap.cdap.common.guice.DFSLocationModule) Injector(com.google.inject.Injector) TwillRunnerService(org.apache.twill.api.TwillRunnerService) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with NotFoundException

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));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) NotFoundException(io.cdap.cdap.common.NotFoundException) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 3 with NotFoundException

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);
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) RunCountResult(io.cdap.cdap.proto.RunCountResult) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) NotFoundException(io.cdap.cdap.common.NotFoundException) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 4 with 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;
}
Also used : MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 5 with NotFoundException

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();
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) URL(java.net.URL)

Aggregations

NotFoundException (io.cdap.cdap.common.NotFoundException)133 HttpResponse (io.cdap.common.http.HttpResponse)43 URL (java.net.URL)38 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)27 ProgramId (io.cdap.cdap.proto.id.ProgramId)26 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)25 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)25 Path (javax.ws.rs.Path)25 BadRequestException (io.cdap.cdap.common.BadRequestException)21 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)21 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)18 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)18 IOException (java.io.IOException)18 GET (javax.ws.rs.GET)18 Test (org.junit.Test)15 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)14 HashMap (java.util.HashMap)14 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)13 ConflictException (io.cdap.cdap.common.ConflictException)13 ArrayList (java.util.ArrayList)13