use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class ImageChangeAction method storeOriginalImageRevision.
private ImageEntity storeOriginalImageRevision(ImageChangeEvent payload, Map<Object, Object> variables) {
ImageEntity imageEntity = imageService.getByStackId(payload.getResourceId());
Long imageEntityId = imageEntity.getId();
List<Number> revisions = auditReader.getRevisions(ImageEntity.class, imageEntityId);
if (!revisions.isEmpty()) {
storeRevisionInfo(variables, imageEntityId, revisions);
} else {
LOGGER.info("No revision found for current image with id [{}]", imageEntityId);
variables.put(ImageChangeActions.ORIGINAL_IMAGE, imageEntity);
}
return imageEntity;
}
use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class ImageChangeAction method doExecute.
@Override
protected void doExecute(StackContext context, ImageChangeEvent payload, Map<Object, Object> variables) throws Exception {
setOperationId(variables, payload.getOperationId());
ImageEntity originalImageEntity = storeOriginalImageRevision(payload, variables);
ImageEntity newImageEntity = imageService.changeImage(context.getStack(), payload.getRequest());
variables.put(ImageChangeActions.IMAGE_CHANGED_IN_DB, Boolean.TRUE);
if (originalImageEntity.equals(newImageEntity)) {
LOGGER.info("New and original image is the same, no change is required");
sendEvent(context, new ImageChangeEvent(IMAGE_CHANGE_NOT_REQUIRED_EVENT.event(), payload.getResourceId(), payload.getRequest()));
} else {
sendEvent(context, new ImageChangeEvent(IMAGE_CHANGED_IN_DB_EVENT.event(), payload.getResourceId(), payload.getRequest()));
}
}
use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class BootstrapServiceTest method testBootstrapWithoutInstanceIds.
@Test
public void testBootstrapWithoutInstanceIds() throws CloudbreakOrchestratorException, IOException {
when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain")));
Stack stack = new Stack();
stack.setCloudPlatform("cloud");
when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
freeIpa.setHostname(HOSTNAME);
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
List<GatewayConfig> gatewayConfigs = List.of();
when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
byte[] bytes = {};
when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenReturn(bytes);
ImageEntity image = new ImageEntity();
image.setOs("ZOS");
when(imageService.getByStack(stack)).thenReturn(image);
when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
underTest.bootstrap(STACK_ID);
ArgumentCaptor<Set<Node>> targetCaptor = ArgumentCaptor.forClass((Class) Set.class);
ArgumentCaptor<Set<Node>> allCaptor = ArgumentCaptor.forClass((Class) Set.class);
ArgumentCaptor<BootstrapParams> bootstrapParamsCaptor = ArgumentCaptor.forClass(BootstrapParams.class);
ArgumentCaptor<ExitCriteriaModel> exitCriteriaModelCaptor = ArgumentCaptor.forClass(ExitCriteriaModel.class);
verify(hostOrchestrator).bootstrapNewNodes(eq(gatewayConfigs), targetCaptor.capture(), allCaptor.capture(), eq(bytes), bootstrapParamsCaptor.capture(), exitCriteriaModelCaptor.capture());
Set<Node> targetNodes = targetCaptor.getValue();
Set<Node> allNodes = allCaptor.getValue();
assertEquals(targetNodes, allNodes);
assertEquals(3, allNodes.size());
assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WITH_FQDN)), hasProperty("hostname", is("instance1")), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WO_FQDN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
assertThat(allNodes, hasItem(allOf(hasProperty("instanceId", is(INSTANCE_WRONG_DOMAIN)), hasProperty("hostname", is(HOSTNAME + '1')), hasProperty("domain", is(DOMAIN)), hasProperty("instanceType", is("GW")), hasProperty("hostGroup", is("TADA")))));
BootstrapParams bootstrapParams = bootstrapParamsCaptor.getValue();
assertTrue(bootstrapParams.isSaltBootstrapFpSupported());
assertTrue(bootstrapParams.isRestartNeededFlagSupported());
assertEquals(image.getOs(), bootstrapParams.getOs());
assertEquals(stack.getCloudPlatform(), bootstrapParams.getCloud());
StackBasedExitCriteriaModel exitCriteriaModel = (StackBasedExitCriteriaModel) exitCriteriaModelCaptor.getValue();
assertEquals(STACK_ID, exitCriteriaModel.getStackId().get());
}
use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class BootstrapServiceTest method testCbOrchestratorExRethrown.
@Test
public void testCbOrchestratorExRethrown() throws CloudbreakOrchestratorException, IOException {
when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(createInstance(INSTANCE_WITH_FQDN, "instance1" + DOMAIN), createInstance(INSTANCE_WO_FQDN, null), createInstance(INSTANCE_WRONG_DOMAIN, "instance.wrong.domain")));
Stack stack = new Stack();
stack.setCloudPlatform("cloud");
when(stackRepository.findById(STACK_ID)).thenReturn(Optional.of(stack));
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
freeIpa.setHostname(HOSTNAME);
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
List<GatewayConfig> gatewayConfigs = List.of();
when(gatewayConfigService.getGatewayConfigs(eq(stack), anySet())).thenReturn(gatewayConfigs);
when(compressUtil.generateCompressedOutputFromFolders("salt-common", "freeipa-salt")).thenThrow(new IOException("wow"));
ImageEntity image = new ImageEntity();
image.setOs("ZOS");
when(imageService.getByStack(stack)).thenReturn(image);
when(hostDiscoveryService.generateHostname(anyString(), any(), anyLong(), anyBoolean())).thenCallRealMethod();
assertThrows(CloudbreakOrchestratorException.class, () -> underTest.bootstrap(STACK_ID));
}
use of com.sequenceiq.freeipa.entity.ImageEntity in project cloudbreak by hortonworks.
the class UsedImagesProviderTest method createImage.
private ImageEntity createImage(String imageId) {
final ImageEntity image = new ImageEntity();
image.setImageId(imageId);
return image;
}
Aggregations