use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class EnvironmentStatusCheckerJob method executeTracedJob.
@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
Long envId = getLocalIdAsLong();
Optional<Environment> environmentOpt = environmentService.findEnvironmentById(envId);
if (environmentOpt.isPresent()) {
Environment environment = environmentOpt.get();
if (flowLogService.isOtherFlowRunning(envId)) {
LOGGER.info("EnvironmentStatusCheckerJob cannot run, because flow is running for environment: {}", environment.getName());
} else {
syncAnEnv(environment);
}
} else {
environmentJobService.unschedule(envId);
LOGGER.warn("EnvironmentStatusCheckerJob cannot run, because environment is not found with id: {}. This env is unscheduled now", envId);
}
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class NetworkCreationHandlerTest method testWithEndpointGatewayAndEnvironmentSubnets.
@Test
public void testWithEndpointGatewayAndEnvironmentSubnets() {
EnvironmentDto environmentDto = createEnvironmentDto();
Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
AwsNetwork network = createNetwork();
Environment environment = createEnvironment(network);
Optional<Environment> environmentOptional = Optional.of(environment);
Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
subnets.putAll(createDefaultPublicSubnets());
when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenReturn(Map.of());
when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
// Testing that underTest.accept() does not throw a BadRequestException
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
assertEquals(0, environmentDto.getNetwork().getEndpointGatewaySubnetMetas().size());
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class NetworkCreationHandlerTest method testHandleValidationFailure.
@Test
public void testHandleValidationFailure() {
EnvironmentDto environmentDto = createEnvironmentDto();
Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
AwsNetwork network = createNetwork();
Environment environment = createEnvironment(network);
Optional<Environment> environmentOptional = Optional.of(environment);
Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenThrow(new BadRequestException("failure"));
when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
ArgumentCaptor<Event<EnvCreationFailureEvent>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus, times(1)).notify(any(Object.class), eventCaptor.capture());
Event<EnvCreationFailureEvent> value = eventCaptor.getValue();
assertTrue(value.getData().getException() instanceof BadRequestException);
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class PublicKeyCreationHandlerTest method acceptTestEnvironmentShouldNotBeUpdatedWhenAuthenticationDoesNotContainManagedKey.
@Test
void acceptTestEnvironmentShouldNotBeUpdatedWhenAuthenticationDoesNotContainManagedKey() {
doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEvent.capture(), any(Headers.class));
EnvironmentAuthentication authentication = new EnvironmentAuthentication();
authentication.setManagedKey(false);
Environment environment = new Environment();
environment.setAuthentication(authentication);
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
underTest.accept(environmentDtoEvent);
verify(eventSender).sendEvent(baseNamedFlowEvent.capture(), headersArgumentCaptor.capture());
verify(environmentResourceService, never()).createAndUpdateSshKey(environment);
verify(environmentService, never()).save(any());
verifyEnvCreationEvent();
}
use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.
the class ResourceEncryptionInitializationHandlerTest method acceptTestEnvironmentShouldNotBeUpdatedWhenCloudPlatformIsNotAzure.
@Test
void acceptTestEnvironmentShouldNotBeUpdatedWhenCloudPlatformIsNotAzure() {
doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), any(Headers.class));
Environment environment = new Environment();
eventDto.setCloudPlatform("Dummy-cloud");
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
underTest.accept(environmentDtoEvent);
verify(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), headersArgumentCaptor.capture());
verify(environmentService, never()).save(any(Environment.class));
verifyEnvCreationEvent();
}
Aggregations