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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations