@Test public void testGetClusterByNameWhenNotPresentInDBThenCBSyncByName() { AutoscaleStackV4Response autoscaleStackV4Response = mock(AutoscaleStackV4Response.class); when(clusterService.findOneByStackNameAndTenant(TEST_CLUSTER_NAME, tenant)).thenReturn(Optional.empty()); when(cloudbreakCommunicator.getAutoscaleClusterByName(TEST_CLUSTER_NAME)).thenReturn(autoscaleStackV4Response); when(autoscaleStackV4Response.getStackType()).thenReturn(StackType.WORKLOAD); when(clusterService.create(autoscaleStackV4Response)).thenReturn(getACluster().get()); Cluster cluster = underTest.getClusterByCrnOrName(NameOrCrn.ofName(TEST_CLUSTER_NAME)); assertEquals("Cluster Name should match", TEST_CLUSTER_NAME, cluster.getStackName()); assertEquals("Cluster CRN should match", TEST_CLUSTER_CRN, cluster.getStackCrn()); }
protected Cluster getClusterByCrnOrName(NameOrCrn nameOrCrn) { return nameOrCrn.hasName() ? clusterService.findOneByStackNameAndTenant(nameOrCrn.getName(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByName(nameOrCrn.getName())) : clusterService.findOneByStackCrnAndTenant(nameOrCrn.getCrn(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByCrn(nameOrCrn.getCrn())); }
AutoScaleClusterCommonService implements ResourceBasedCrnProvider { protected Cluster getClusterByCrnOrName(NameOrCrn nameOrCrn) { return nameOrCrn.hasName() ? clusterService.findOneByStackNameAndTenant(nameOrCrn.getName(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByName(nameOrCrn.getName())) : clusterService.findOneByStackCrnAndTenant(nameOrCrn.getCrn(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByCrn(nameOrCrn.getCrn())); } }
AutoScaleClusterCommonService implements ResourceBasedCrnProvider { protected Cluster getClusterByCrnOrName(NameOrCrn nameOrCrn) { return nameOrCrn.hasName() ? clusterService.findOneByStackNameAndTenant(nameOrCrn.getName(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByName(nameOrCrn.getName())) : clusterService.findOneByStackCrnAndTenant(nameOrCrn.getCrn(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByCrn(nameOrCrn.getCrn())); }  }
AutoScaleClusterCommonService implements ResourceBasedCrnProvider { protected Cluster getClusterByCrnOrName(NameOrCrn nameOrCrn) { return nameOrCrn.hasName() ? clusterService.findOneByStackNameAndTenant(nameOrCrn.getName(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByName(nameOrCrn.getName())) : clusterService.findOneByStackCrnAndTenant(nameOrCrn.getCrn(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByCrn(nameOrCrn.getCrn())); }  List<Cluster> getDistroXClusters(); Cluster getCluster(Long clusterId); @Retryable(value = NotFoundException.class, maxAttempts = 3, backoff = @Backoff(delay = 5000)) Cluster getClusterByStackCrn(String stackCrn); @Retryable(value = NotFoundException.class, maxAttempts = 3, backoff = @Backoff(delay = 5000)) Cluster getClusterByStackName(String stackName); void deleteCluster(Long clusterId); Cluster setState(Long clusterId, StateJson stateJson); Cluster setAutoscaleState(Long clusterId, AutoscaleClusterState autoscaleState); Cluster setAutoscaleState(Long clusterId, Boolean enableAutoScaling); void deleteAlertsForClusterCrn(String stackCrn); void deleteAlertsForClusterName(String stackName); void createLoadAlerts(Long clusterId, List<LoadAlert> loadAlerts); void createTimeAlerts(Long clusterId, List<TimeAlert> timeAlerts); @Override AuthorizationResourceType getResourceType(); @Override @Retryable(value = NotFoundException.class, maxAttempts = 3, backoff = @Backoff(delay = 5000)) String getResourceCrnByResourceName(String clusterName); }
AutoScaleClusterCommonService implements ResourceBasedCrnProvider { protected Cluster getClusterByCrnOrName(NameOrCrn nameOrCrn) { return nameOrCrn.hasName() ? clusterService.findOneByStackNameAndTenant(nameOrCrn.getName(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByName(nameOrCrn.getName())) : clusterService.findOneByStackCrnAndTenant(nameOrCrn.getCrn(), restRequestThreadLocalService.getCloudbreakTenant()) .orElseGet(() -> syncCBClusterByCrn(nameOrCrn.getCrn())); }  List<Cluster> getDistroXClusters(); Cluster getCluster(Long clusterId); @Retryable(value = NotFoundException.class, maxAttempts = 3, backoff = @Backoff(delay = 5000)) Cluster getClusterByStackCrn(String stackCrn); @Retryable(value = NotFoundException.class, maxAttempts = 3, backoff = @Backoff(delay = 5000)) Cluster getClusterByStackName(String stackName); void deleteCluster(Long clusterId); Cluster setState(Long clusterId, StateJson stateJson); Cluster setAutoscaleState(Long clusterId, AutoscaleClusterState autoscaleState); Cluster setAutoscaleState(Long clusterId, Boolean enableAutoScaling); void deleteAlertsForClusterCrn(String stackCrn); void deleteAlertsForClusterName(String stackName); void createLoadAlerts(Long clusterId, List<LoadAlert> loadAlerts); void createTimeAlerts(Long clusterId, List<TimeAlert> timeAlerts); @Override AuthorizationResourceType getResourceType(); @Override @Retryable(value = NotFoundException.class, maxAttempts = 3, backoff = @Backoff(delay = 5000)) String getResourceCrnByResourceName(String clusterName);  }