Search in sources :

Example 56 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class NetworkServiceTest method testAzureMultipleNetworkWithSameId.

@Test
public void testAzureMultipleNetworkWithSameId() {
    Stack stack = new Stack();
    stack.setCloudPlatform(PLATFORM);
    stack.setRegion(REGION);
    stack.setPlatformvariant(PLATFORM);
    Credential credential = new Credential(PLATFORM, "", "", "", "acc");
    ExtendedCloudCredential extendedCred = new ExtendedCloudCredential(new CloudCredential(), PLATFORM, "", "", "", new ArrayList<>());
    CloudSubnet subnet1 = new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.1.0.0/24");
    CloudSubnet subnet2 = new CloudSubnet(SUBNET_2, SUBNET_2, "", "10.1.1.0/24");
    CloudSubnet subnet3 = new CloudSubnet("indifferent", "indifferent", "", "10.1.2.0/24");
    CloudNetwork cloudNetwork1 = new CloudNetwork("/rg1/" + NETWORK_ID, "/rg1/" + NETWORK_ID, Set.of(subnet1, subnet2, subnet3), Map.of());
    CloudNetwork cloudNetwork2 = new CloudNetwork("/rg2/" + NETWORK_ID, "/rg2/" + NETWORK_ID, Set.of(new CloudSubnet(SUBNET_1, SUBNET_1, "", "10.2.0.0/24"), new CloudSubnet("test", "test")), Map.of());
    Map<String, Set<CloudNetwork>> cloudNets = Map.of(REGION, Set.of(cloudNetwork1, cloudNetwork2));
    CloudNetworks cloudNetworks = new CloudNetworks(cloudNets);
    when(credentialService.getCredentialByEnvCrn(ENV_CRN)).thenReturn(credential);
    when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCred);
    when(cloudParameterService.getCloudNetworks(eq(extendedCred), eq(REGION), eq(PLATFORM), any())).thenReturn(cloudNetworks);
    when(networkFilterProviderMap.get(any())).thenReturn(null);
    Multimap<String, String> filteredSubnetWithCidr = underTest.getFilteredSubnetWithCidr(ENV_CRN, stack, NETWORK_ID, List.of(SUBNET_1, SUBNET_2));
    assertEquals(3, filteredSubnetWithCidr.size());
    assertEquals(2, filteredSubnetWithCidr.get(subnet1.getId()).size());
    assertTrue(filteredSubnetWithCidr.get(subnet1.getId()).contains(subnet1.getCidr()));
    assertTrue(filteredSubnetWithCidr.get(subnet1.getId()).contains("10.2.0.0/24"));
    assertEquals(1, filteredSubnetWithCidr.get(subnet2.getId()).size());
    assertEquals(subnet2.getCidr(), filteredSubnetWithCidr.get(subnet2.getId()).stream().findFirst().get());
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.freeipa.dto.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Set(java.util.Set) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 57 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRenameStackIfNeededWhenAlreadyRenamed.

@Test
public void testRenameStackIfNeededWhenAlreadyRenamed() {
    Stack stack = createStack(DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
    Long terminationTime = 1638311233640L;
    String stackName = "freeipa_" + terminationTime;
    stack.setName(stackName);
    stack.setTerminated(terminationTime);
    underTest.renameStackIfNeeded(stack);
    verify(terminationService, never()).finalizeTermination(any());
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 58 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRebuild.

@Test
public void testRebuild() throws Exception {
    Stack stack = createStack(Status.DELETE_COMPLETED, List.of(InstanceStatus.TERMINATED, InstanceStatus.TERMINATED), 2);
    CreateFreeIpaRequest createFreeIpaRequest = new CreateFreeIpaRequest();
    DescribeFreeIpaResponse response = new DescribeFreeIpaResponse();
    when(stackService.getByCrnAndAccountIdEvenIfTerminated(ENVIRONMENT_ID1, ACCOUNT_ID, FREEIPA_CRN)).thenReturn(stack);
    when(stackService.findByEnvironmentCrnAndAccountId(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(Optional.empty());
    when(stackToCreateFreeIpaRequestConverter.convert(eq(stack))).thenReturn(createFreeIpaRequest);
    when(freeIpaCreationService.launchFreeIpa(eq(createFreeIpaRequest), eq(ACCOUNT_ID))).thenReturn(response);
    when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    RebuildRequest rebuildRequest = new RebuildRequest();
    rebuildRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
    rebuildRequest.setSourceCrn(FREEIPA_CRN);
    assertEquals(response, underTest.rebuild(ACCOUNT_ID, rebuildRequest));
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) RebuildRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.rebuild.RebuildRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 59 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairInstancesWithForce.

@Test
void testRepairInstancesWithForce() {
    Stack stack = createStack(Status.AVAILABLE, List.of(InstanceStatus.CREATED, InstanceStatus.CREATED));
    List<String> instanceIds = List.of("i-2");
    OperationStatus operationStatus = new OperationStatus();
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
    when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
    when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
    when(stackUpdater.updateStackStatus(anyLong(), any(), any())).thenReturn(stack);
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setForceRepair(true);
    request.setInstanceIds(instanceIds);
    request.setEnvironmentCrn(ENVIRONMENT_ID1);
    assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, request));
    ArgumentCaptor acAcceptable = ArgumentCaptor.forClass(Acceptable.class);
    verify(flowManager).notify(eq("REPAIR_TRIGGER_EVENT"), (Acceptable) acAcceptable.capture());
    assertTrue(acAcceptable.getValue() instanceof RepairEvent);
    RepairEvent repairEvent = (RepairEvent) acAcceptable.getValue();
    assertEquals(instanceIds, repairEvent.getRepairInstanceIds());
    verify(stackUpdater).updateStackStatus(eq(STACK_ID), eq(DetailedStackStatus.REPAIR_REQUESTED), any());
}
Also used : ArgumentCaptor(org.mockito.ArgumentCaptor) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) RepairEvent(com.sequenceiq.freeipa.flow.freeipa.repair.event.RepairEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 60 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class RepairInstancesServiceTest method testRepairAndAutodetectBadInstances.

@Test
public void testRepairAndAutodetectBadInstances() throws Exception {
    Stack stack = createStack(Status.UNHEALTHY, List.of(InstanceStatus.DELETED_ON_PROVIDER_SIDE, InstanceStatus.CREATED));
    OperationStatus operationStatus = new OperationStatus();
    RepairInstancesRequest repairInstancesRequest = new RepairInstancesRequest();
    repairInstancesRequest.setEnvironmentCrn(ENVIRONMENT_ID1);
    repairInstancesRequest.setForceRepair(false);
    when(stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(stack);
    when(healthDetailsService.getHealthDetails(ENVIRONMENT_ID1, ACCOUNT_ID)).thenReturn(createHealthDetails(InstanceStatus.DELETED_ON_PROVIDER_SIDE, InstanceStatus.CREATED));
    when(entitlementService.freeIpaHaRepairEnabled(any())).thenReturn(Boolean.TRUE);
    when(operationService.startOperation(any(), any(), any(), any())).thenReturn(createOperation());
    when(operationToOperationStatusConverter.convert(any())).thenReturn(operationStatus);
    assertEquals(operationStatus, underTest.repairInstances(ACCOUNT_ID, repairInstancesRequest));
    verify(flowManager, times(1)).notify(eq(REPAIR_TRIGGER_EVENT), any());
}
Also used : OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)468 Test (org.junit.jupiter.api.Test)237 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)107 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)63 Map (java.util.Map)63 Bean (org.springframework.context.annotation.Bean)50 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)45 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)41 List (java.util.List)37 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)34 Inject (javax.inject.Inject)30 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 Collectors (java.util.stream.Collectors)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 Set (java.util.Set)28 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)25 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)25 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)24 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)23