Search in sources :

Example 1 with ProvisionerSpecification

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification in project cdap by caskdata.

the class ProfileHttpHandlerTest method testPutAndDeleteProfiles.

@Test
public void testPutAndDeleteProfiles() throws Exception {
    Profile invalidProfile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("nonExisting", PROPERTY_SUMMARIES));
    // adding a profile with non-existing provisioner should get a 400
    putProfile(NamespaceId.DEFAULT.profile(invalidProfile.getName()), invalidProfile, HttpURLConnection.HTTP_BAD_REQUEST);
    // put a profile with the mock provisioner
    Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
    ProfileId expectedProfileId = NamespaceId.DEFAULT.profile(expected.getName());
    putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
    // get the profile
    Profile actual = getProfile(expectedProfileId, HttpURLConnection.HTTP_OK).get();
    Assert.assertEquals(expected, actual);
    // list all profiles, should get 2 profiles
    List<Profile> profiles = listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK);
    Set<Profile> expectedList = ImmutableSet.of(Profile.NATIVE, expected);
    Assert.assertEquals(expectedList.size(), profiles.size());
    Assert.assertEquals(expectedList, new HashSet<>(profiles));
    // adding the same profile should still succeed
    putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
    // get non-existing profile should get a 404
    deleteProfile(NamespaceId.DEFAULT.profile("nonExisting"), HttpURLConnection.HTTP_NOT_FOUND);
    // delete the profile should fail first time since it is by default enabled
    deleteProfile(expectedProfileId, HttpURLConnection.HTTP_CONFLICT);
    // disable the profile then delete should work
    disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    deleteProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    Assert.assertEquals(Collections.emptyList(), listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_OK));
    // if given some unrelated json, it should return a 400 instead of 500
    ProvisionerSpecification spec = new MockProvisioner().getSpec();
    ProvisionerDetail test = new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), new ArrayList<>(), null, null, false);
    putProfile(NamespaceId.DEFAULT.profile(test.getName()), test, HttpURLConnection.HTTP_BAD_REQUEST);
    doAs(READ_ONLY_USER_NAME, () -> {
        putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_FORBIDDEN);
        disableProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
        enableProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
        deleteProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
    });
    doAs(READ_WRITE_USER_NAME, () -> {
        putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
        disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
        enableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
        disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
        deleteProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
    });
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) MockProvisioner(io.cdap.cdap.internal.provision.MockProvisioner) Profile(io.cdap.cdap.proto.profile.Profile) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail) Test(org.junit.Test)

Example 2 with ProvisionerSpecification

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification 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 3 with ProvisionerSpecification

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification 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 4 with ProvisionerSpecification

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification 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)

Aggregations

ProvisionerDetail (io.cdap.cdap.proto.provisioner.ProvisionerDetail)4 ProvisionerSpecification (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification)4 Test (org.junit.Test)3 MockProvisioner (io.cdap.cdap.internal.provision.MockProvisioner)2 MockProvisionerWithCpus (io.cdap.cdap.internal.provision.MockProvisionerWithCpus)1 ProfileId (io.cdap.cdap.proto.id.ProfileId)1 Profile (io.cdap.cdap.proto.profile.Profile)1 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)1 Provisioner (io.cdap.cdap.runtime.spi.provisioner.Provisioner)1 ProvisionerSystemContext (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1