Search in sources :

Example 6 with ProvisionerDetail

use of io.cdap.cdap.proto.provisioner.ProvisionerDetail in project cdap by cdapio.

the class ProgramLifecycleService method createProgramOptions.

@VisibleForTesting
ProgramOptions createProgramOptions(ProgramId programId, Map<String, String> userArgs, Map<String, String> sysArgs, boolean debug) throws NotFoundException, ProfileConflictException {
    ProfileId profileId = SystemArguments.getProfileIdForProgram(programId, userArgs);
    Map<String, String> profileProperties = SystemArguments.getProfileProperties(userArgs);
    Profile profile = profileService.getProfile(profileId, profileProperties);
    if (profile.getStatus() == ProfileStatus.DISABLED) {
        throw new ProfileConflictException(String.format("Profile %s in namespace %s is disabled. It cannot be " + "used to start the program %s", profileId.getProfile(), profileId.getNamespace(), programId.toString()), profileId);
    }
    ProvisionerDetail spec = provisioningService.getProvisionerDetail(profile.getProvisioner().getName());
    if (spec == null) {
        throw new NotFoundException(String.format("Provisioner '%s' not found.", profile.getProvisioner().getName()));
    }
    // get and add any user overrides for profile properties
    Map<String, String> systemArgs = new HashMap<>(sysArgs);
    // add profile properties to the system arguments
    SystemArguments.addProfileArgs(systemArgs, profile);
    // Set the ClusterMode. If it is NATIVE profile, then it is ON_PREMISE, otherwise is ISOLATED
    // This should probably move into the provisioner later once we have a better contract for the
    // provisioner to actually pick what launching mechanism it wants to use.
    systemArgs.put(ProgramOptionConstants.CLUSTER_MODE, (ProfileId.NATIVE.equals(profileId) ? ClusterMode.ON_PREMISE : ClusterMode.ISOLATED).name());
    ProgramSpecification programSpecification = getProgramSpecificationWithoutAuthz(programId);
    if (programSpecification == null) {
        throw new NotFoundException(programId);
    }
    addAppCDAPVersion(programId, systemArgs);
    // put all the plugin requirements if any involved in the run
    systemArgs.put(ProgramOptionConstants.PLUGIN_REQUIREMENTS, GSON.toJson(getPluginRequirements(programSpecification)));
    return new SimpleProgramOptions(programId, new BasicArguments(systemArgs), new BasicArguments(userArgs), debug);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) HashMap(java.util.HashMap) NotFoundException(io.cdap.cdap.common.NotFoundException) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with ProvisionerDetail

use of io.cdap.cdap.proto.provisioner.ProvisionerDetail in project cdap by caskdata.

the class ProvisionerHttpHandlerTest method testListAndGetProvisioners.

@Test
public void testListAndGetProvisioners() throws Exception {
    // in unit test, we have the mock provisioners currently
    ProvisionerSpecification spec = new MockProvisioner().getSpec();
    ProvisionerDetail expected = new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), new ArrayList<>(), null, null, false);
    ProvisionerSpecification specWithCpus = new MockProvisionerWithCpus().getSpec();
    ProvisionerDetail expectedWithCpus = new ProvisionerDetail(specWithCpus.getName(), specWithCpus.getLabel(), specWithCpus.getDescription(), new ArrayList<>(), null, null, false);
    List<ProvisionerDetail> details = listProvisioners();
    Assert.assertEquals(ImmutableList.of(expected, expectedWithCpus), details);
    // get a non-existing provisioner should get a 404
    getProvisioner("nonExisting", 404);
    // get the mock provisioner
    Assert.assertEquals(expected, getProvisioner(MockProvisioner.NAME, 200));
}
Also used : MockProvisionerWithCpus(io.cdap.cdap.internal.provision.MockProvisionerWithCpus) ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) MockProvisioner(io.cdap.cdap.internal.provision.MockProvisioner) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) Test(org.junit.Test)

Example 8 with ProvisionerDetail

use of io.cdap.cdap.proto.provisioner.ProvisionerDetail in project cdap by caskdata.

the class ProvisioningService method initializeProvisioners.

/**
 * Reloads provisioners in the extension directory. Any new provisioners will be added and any deleted provisioners
 * will be removed. Loaded provisioners will be initialized.
 */
private void initializeProvisioners() {
    Map<String, Provisioner> provisioners = provisionerProvider.loadProvisioners();
    Map<String, ProvisionerConfig> provisionerConfigs = provisionerConfigProvider.loadProvisionerConfigs(provisioners.values());
    LOG.debug("Provisioners = {}", provisioners);
    Map<String, ProvisionerDetail> details = new HashMap<>(provisioners.size());
    for (Map.Entry<String, Provisioner> provisionerEntry : provisioners.entrySet()) {
        String provisionerName = provisionerEntry.getKey();
        Provisioner provisioner = provisionerEntry.getValue();
        ProvisionerSystemContext provisionerSystemContext = new DefaultSystemProvisionerContext(cConf, provisionerName);
        try {
            provisioner.initialize(provisionerSystemContext);
        } catch (RuntimeException e) {
            LOG.warn("Error initializing the {} provisioner. It will not be available for use.", provisionerName, e);
            provisioners.remove(provisionerName);
            continue;
        }
        ProvisionerSpecification spec = provisioner.getSpec();
        ProvisionerConfig config = provisionerConfigs.getOrDefault(provisionerName, new ProvisionerConfig(new ArrayList<>(), null, null, false));
        details.put(provisionerName, new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), config.getConfigurationGroups(), config.getFilters(), config.getIcon(), config.isBeta()));
    }
    provisionerInfo.set(new ProvisionerInfo(provisioners, details));
}
Also used : ProvisionerSystemContext(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext) ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) HashMap(java.util.HashMap) Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail)

Example 9 with ProvisionerDetail

use of io.cdap.cdap.proto.provisioner.ProvisionerDetail in project cdap by caskdata.

the class ProvisioningServiceTest method testGetSpecs.

@Test
public void testGetSpecs() {
    Collection<ProvisionerDetail> specs = provisioningService.getProvisionerDetails();
    Assert.assertEquals(2, specs.size());
    ProvisionerSpecification spec = new MockProvisioner().getSpec();
    ProvisionerDetail expected = new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), new ArrayList<>(), null, null, false);
    Assert.assertEquals(expected, specs.iterator().next());
    Assert.assertEquals(expected, provisioningService.getProvisionerDetail(MockProvisioner.NAME));
    Assert.assertNull(provisioningService.getProvisionerDetail("abc"));
}
Also used : ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) Test(org.junit.Test)

Example 10 with ProvisionerDetail

use of io.cdap.cdap.proto.provisioner.ProvisionerDetail in project cdap by cdapio.

the class ProvisioningServiceTest method testGetSpecs.

@Test
public void testGetSpecs() {
    Collection<ProvisionerDetail> specs = provisioningService.getProvisionerDetails();
    Assert.assertEquals(2, specs.size());
    ProvisionerSpecification spec = new MockProvisioner().getSpec();
    ProvisionerDetail expected = new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), new ArrayList<>(), null, null, false);
    Assert.assertEquals(expected, specs.iterator().next());
    Assert.assertEquals(expected, provisioningService.getProvisionerDetail(MockProvisioner.NAME));
    Assert.assertNull(provisioningService.getProvisionerDetail("abc"));
}
Also used : ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) Test(org.junit.Test)

Aggregations

ProvisionerDetail (io.cdap.cdap.proto.provisioner.ProvisionerDetail)12 ProvisionerSpecification (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification)8 Test (org.junit.Test)6 NotFoundException (io.cdap.cdap.common.NotFoundException)4 MockProvisioner (io.cdap.cdap.internal.provision.MockProvisioner)4 ProfileId (io.cdap.cdap.proto.id.ProfileId)4 Profile (io.cdap.cdap.proto.profile.Profile)4 HashMap (java.util.HashMap)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)2 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)2 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)2 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)2 MockProvisionerWithCpus (io.cdap.cdap.internal.provision.MockProvisionerWithCpus)2 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)2 Provisioner (io.cdap.cdap.runtime.spi.provisioner.Provisioner)2 ProvisionerSystemContext (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2