Search in sources :

Example 11 with ProvisionerInfo

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

the class ProvisioningServiceTest method testCancelProvision.

@Test
public void testCancelProvision() throws InterruptedException, ExecutionException, TimeoutException, IOException {
    ProvisionerInfo provisionerInfo = new MockProvisioner.PropertyBuilder().waitCreate(1, TimeUnit.MINUTES).build();
    TaskFields taskFields = createTaskInfo(provisionerInfo);
    ProvisionRequest provisionRequest = new ProvisionRequest(taskFields.programRunId, taskFields.programOptions, taskFields.programDescriptor, "Bob");
    Runnable task = TransactionRunners.run(transactionRunner, context -> {
        return provisioningService.provision(provisionRequest, context);
    });
    task.run();
    Assert.assertTrue(provisioningService.cancelProvisionTask(taskFields.programRunId).isPresent());
    // check that the state of the task is cancelled
    ProvisioningTaskKey taskKey = new ProvisioningTaskKey(taskFields.programRunId, ProvisioningOp.Type.PROVISION);
    waitForExpectedProvisioningState(taskKey, ProvisioningOp.Status.CANCELLED);
}
Also used : ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Test(org.junit.Test)

Example 12 with ProvisionerInfo

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

the class ProvisioningServiceTest method testCancelDeprovision.

@Test
public void testCancelDeprovision() throws Exception {
    ProvisionerInfo provisionerInfo = new MockProvisioner.PropertyBuilder().waitDelete(1, TimeUnit.MINUTES).build();
    TaskFields taskFields = testProvision(ProvisioningOp.Status.CREATED, provisionerInfo);
    Runnable task = TransactionRunners.run(transactionRunner, context -> {
        return provisioningService.deprovision(taskFields.programRunId, context, t -> {
        });
    });
    task.run();
    Assert.assertTrue(provisioningService.cancelDeprovisionTask(taskFields.programRunId).isPresent());
    // check that the state of the task is cancelled
    ProvisioningTaskKey taskKey = new ProvisioningTaskKey(taskFields.programRunId, ProvisioningOp.Type.DEPROVISION);
    waitForExpectedProvisioningState(taskKey, ProvisioningOp.Status.CANCELLED);
}
Also used : ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Test(org.junit.Test)

Example 13 with ProvisionerInfo

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

the class ProvisioningServiceTest method testRetryableFailures.

@Test
public void testRetryableFailures() throws Exception {
    // will throw a retryable exception every other method call
    ProvisionerInfo provisionerInfo = new MockProvisioner.PropertyBuilder().failRetryablyEveryN(2).build();
    TaskFields taskFields = testProvision(ProvisioningOp.Status.CREATED, provisionerInfo);
    testDeprovision(taskFields.programRunId, ProvisioningOp.Status.DELETED);
}
Also used : ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Test(org.junit.Test)

Example 14 with ProvisionerInfo

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

the class ProfileServiceTest method testProfileUpdateDisallowed.

@Test(expected = MethodNotAllowedException.class)
public void testProfileUpdateDisallowed() throws Exception {
    ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile");
    Profile profile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
    profileService.saveProfile(profileId, profile);
    CConfiguration cConfWithProfileCreationDisabled = CConfiguration.copy(cConf);
    cConfWithProfileCreationDisabled.setBoolean(Constants.Profile.UPDATE_ALLOWED, false);
    ProfileService service = new ProfileService(cConfWithProfileCreationDisabled, getInjector().getInstance(MetricsSystemClient.class), getInjector().getInstance(TransactionRunner.class));
    Profile newProfile = new Profile("MyProfile", "label", "my new profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
    // Update the profile
    service.saveProfile(profileId, newProfile);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) MetricsSystemClient(io.cdap.cdap.api.metrics.MetricsSystemClient) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 15 with ProvisionerInfo

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

the class ProfileService method getProfile.

/**
 * Get the profile information about the given profile with property overrides. If a non-editable property is
 * in the overrides, it will be ignored, but a message will be logged.
 *
 * @param profileId the id of the profile to look up
 * @param overrides overrides to the profile properties
 * @return the profile information about the given profile
 * @throws NotFoundException if the profile is not found
 */
public Profile getProfile(ProfileId profileId, Map<String, String> overrides) throws NotFoundException {
    Profile storedProfile = getProfile(profileId);
    List<ProvisionerPropertyValue> properties = new ArrayList<>();
    Set<String> remainingOverrides = new HashSet<>(overrides.keySet());
    // add all  properties from the stored profile
    for (ProvisionerPropertyValue storedProperty : storedProfile.getProvisioner().getProperties()) {
        String propertyName = storedProperty.getName();
        String storedVal = storedProperty.getValue();
        if (!storedProperty.isEditable()) {
            if (overrides.containsKey(propertyName)) {
                LOG.info("Profile property {} cannot be edited. The original value will be used.", propertyName);
            }
            properties.add(storedProperty);
        } else {
            String val = overrides.getOrDefault(propertyName, storedVal);
            properties.add(new ProvisionerPropertyValue(propertyName, val, true));
        }
        remainingOverrides.remove(propertyName);
    }
    // add all remaining overrides
    for (String propertyName : remainingOverrides) {
        properties.add(new ProvisionerPropertyValue(propertyName, overrides.get(propertyName), true));
    }
    ProvisionerInfo provisionerInfo = new ProvisionerInfo(storedProfile.getProvisioner().getName(), properties);
    return new Profile(storedProfile.getName(), storedProfile.getLabel(), storedProfile.getDescription(), storedProfile.getScope(), storedProfile.getStatus(), provisionerInfo, storedProfile.getCreatedTsSeconds());
}
Also used : ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) Profile(io.cdap.cdap.proto.profile.Profile) HashSet(java.util.HashSet)

Aggregations

ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)44 Test (org.junit.Test)40 Profile (io.cdap.cdap.proto.profile.Profile)32 ProfileId (io.cdap.cdap.proto.id.ProfileId)26 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)12 ArrayList (java.util.ArrayList)12 NotFoundException (io.cdap.cdap.common.NotFoundException)6 BootstrapStepResult (io.cdap.cdap.proto.bootstrap.BootstrapStepResult)6 MetricsSystemClient (io.cdap.cdap.api.metrics.MetricsSystemClient)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 TransactionRunner (io.cdap.cdap.spi.data.transaction.TransactionRunner)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)2 BadRequestException (io.cdap.cdap.common.BadRequestException)2 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)2 MockProvisioner (io.cdap.cdap.internal.provision.MockProvisioner)2 ProgramType (io.cdap.cdap.proto.ProgramType)2 ProgramId (io.cdap.cdap.proto.id.ProgramId)2 ProvisionerDetail (io.cdap.cdap.proto.provisioner.ProvisionerDetail)2