Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
CLOUD-93367 removed unused jsons on provider side
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Doktorics authored and keyki committed Feb 12, 2018
1 parent 526833a commit fa8417f
Show file tree
Hide file tree
Showing 57 changed files with 2,079 additions and 9,113 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.sequenceiq.cloudbreak.cloud;

import static com.sequenceiq.cloudbreak.cloud.model.Platform.platform;
import static org.apache.commons.lang3.StringUtils.isNoneEmpty;
import static org.springframework.util.StringUtils.isEmpty;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -16,22 +12,18 @@
import com.google.common.collect.Maps;
import com.sequenceiq.cloudbreak.api.model.SpecialParameters;
import com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone;
import com.sequenceiq.cloudbreak.cloud.model.AvailabilityZones;
import com.sequenceiq.cloudbreak.cloud.model.DiskTypes;
import com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterRequest;
import com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse;
import com.sequenceiq.cloudbreak.cloud.model.Platform;
import com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrator;
import com.sequenceiq.cloudbreak.cloud.model.Region;
import com.sequenceiq.cloudbreak.cloud.model.RegionSpecification;
import com.sequenceiq.cloudbreak.cloud.model.Regions;
import com.sequenceiq.cloudbreak.cloud.model.RegionsSpecification;
import com.sequenceiq.cloudbreak.cloud.model.ScriptParams;
import com.sequenceiq.cloudbreak.cloud.model.StackParamValidation;
import com.sequenceiq.cloudbreak.cloud.model.StringTypesCompare;
import com.sequenceiq.cloudbreak.cloud.model.TagSpecification;
import com.sequenceiq.cloudbreak.cloud.model.VmRecommendations;
import com.sequenceiq.cloudbreak.cloud.model.VmTypes;
import com.sequenceiq.cloudbreak.cloud.model.generic.StringType;
import com.sequenceiq.cloudbreak.util.JsonUtil;

Expand All @@ -54,34 +46,6 @@ public interface PlatformParameters {
*/
DiskTypes diskTypes();

/**
* Regions of a platform
*
* @return the {@link Regions} of a platform
*/
Regions regions();

/**
* Virtual machine types of a platform
*
* @return the {@link VmTypes} of a platform
*/
VmTypes vmTypes(Boolean extended);

/**
* Virtual machine types of a platform in availability zones.
*
* @return the {@link AvailabilityZone}, {@link VmTypes} map of a platform
*/
Map<AvailabilityZone, VmTypes> vmTypesPerAvailabilityZones(Boolean extended);

/**
* Return the availability zones of a platform
*
* @return the {@link AvailabilityZones} of a platform
*/
AvailabilityZones availabilityZones();

/**
* Return the definition of a resource in JSON format.
*
Expand Down Expand Up @@ -118,10 +82,6 @@ public interface PlatformParameters {
*/
VmRecommendations recommendedVms();

String getDefaultRegionsConfigString();

String getDefaultRegionString();

String platforName();

default SpecialParameters specialParameters() {
Expand All @@ -143,30 +103,6 @@ default <S extends StringType, O> Map<S, O> sortMap(Map<S, O> unsortMap) {
return treeMap;
}

default Region getRegionByName(String name) {
for (Region region : regions().types()) {
if (name.equals(region.value())) {
return region;
}
}
return null;
}

default Region getDefaultRegion() {
Map<Platform, Region> regions = Maps.newHashMap();
if (isNoneEmpty(getDefaultRegionsConfigString())) {
for (String entry : getDefaultRegionsConfigString().split(",")) {
String[] keyValue = entry.split(":");
regions.put(platform(keyValue[0]), Region.region(keyValue[1]));
}
Region platformRegion = regions.get(platform(platforName()));
if (platformRegion != null && !isEmpty(platformRegion.value())) {
return getRegionByName(platformRegion.value());
}
}
return getRegionByName(getDefaultRegionString());
}

default <T extends StringType> T nthElement(Collection<T> data, int n) {
return data.stream().skip(n).findFirst().orElse(null);
}
Expand All @@ -188,5 +124,4 @@ default Map<Region, List<AvailabilityZone>> readRegions(String zone) {
}
return sortMap(regions);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import static com.sequenceiq.cloudbreak.cloud.model.DiskType.diskType;
import static com.sequenceiq.cloudbreak.cloud.model.DisplayName.displayName;
import static com.sequenceiq.cloudbreak.cloud.model.Orchestrator.orchestrator;
import static com.sequenceiq.cloudbreak.cloud.model.Region.region;
import static com.sequenceiq.cloudbreak.cloud.model.VmType.vmType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -18,20 +15,14 @@
import org.junit.Test;

import com.google.common.collect.Lists;
import com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone;
import com.sequenceiq.cloudbreak.cloud.model.AvailabilityZones;
import com.sequenceiq.cloudbreak.cloud.model.DiskType;
import com.sequenceiq.cloudbreak.cloud.model.DiskTypes;
import com.sequenceiq.cloudbreak.cloud.model.DisplayName;
import com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrator;
import com.sequenceiq.cloudbreak.cloud.model.Region;
import com.sequenceiq.cloudbreak.cloud.model.Regions;
import com.sequenceiq.cloudbreak.cloud.model.ScriptParams;
import com.sequenceiq.cloudbreak.cloud.model.StackParamValidation;
import com.sequenceiq.cloudbreak.cloud.model.TagSpecification;
import com.sequenceiq.cloudbreak.cloud.model.VmRecommendations;
import com.sequenceiq.cloudbreak.cloud.model.VmType;
import com.sequenceiq.cloudbreak.cloud.model.VmTypes;
import com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType;
import com.sequenceiq.cloudbreak.common.type.OrchestratorConstants;

Expand All @@ -44,36 +35,16 @@ public void before() {
underTest = new TestPlatformParameters();
}

@Test
public void getRegionByNameIfValueConfigured() {
Region defaultRegion = underTest.getDefaultRegion();
Assert.assertEquals(Region.region("testRegion-4"), defaultRegion);
}

@Test
public void getRegionByNameIfValueNotConfigured() {
underTest.setDefaultRegionsConfigString(null);

Region defaultRegion = underTest.getDefaultRegion();
Assert.assertEquals(Region.region("testRegion-0"), defaultRegion);
}

@Test
public void getRegionByNameIsExist() {
Region region = underTest.getRegionByName("testRegion-0");
Assert.assertEquals(Region.region("testRegion-0"), region);
}

@Test
public void getRegionByNameIsNotExist() {
Region region = underTest.getRegionByName("testRegion-99");
Assert.assertEquals(null, region);
DiskTypes diskTypes = underTest.diskTypes();
Assert.assertEquals(1, diskTypes.displayNames().entrySet().size());
Assert.assertEquals(1, diskTypes.diskMapping().entrySet().size());
Assert.assertEquals("testDiskType", diskTypes.defaultType().value());
}

static class TestPlatformParameters implements PlatformParameters {

private String regionDefinition = "test:testRegion-4";

@Override
public ScriptParams scriptParams() {
return new ScriptParams("testDiskPrefix", 1);
Expand All @@ -92,59 +63,6 @@ public DiskTypes diskTypes() {
return new DiskTypes(Arrays.asList(diskType), diskType, stringVolumeParameterTypeMap, displayNames);
}

@Override
public Regions regions() {
List<Region> regions = new ArrayList<>();
Region defaultRegion = null;
for (int i = 0; i < 10; i++) {
if (i == 0) {
defaultRegion = region(String.format("testRegion-%s", i));
}
regions.add(region(String.format("testRegion-%s", i)));
}
Map<Region, DisplayName> map = new HashMap<>();
for (Region region : regions) {
map.put(region, displayName(region.value()));
}
return new Regions(regions, defaultRegion, map);
}

@Override
public VmTypes vmTypes(Boolean extended) {
List<VmType> vmTypes = new ArrayList<>();
VmType defaultVmType = null;
for (int i = 0; i < 10; i++) {
if (i == 0) {
defaultVmType = vmType(String.format("testVmType-%s", i));
}
vmTypes.add(vmType(String.format("testVmType-%s", i)));
}

return new VmTypes(vmTypes, defaultVmType);
}

@Override
public Map<AvailabilityZone, VmTypes> vmTypesPerAvailabilityZones(Boolean extended) {
Map<AvailabilityZone, VmTypes> availabilityZoneVmTypesMap = new HashMap<>();
for (AvailabilityZone availabilityZone : availabilityZones().getAllAvailabilityZone()) {
availabilityZoneVmTypesMap.put(availabilityZone, vmTypes(false));
}
return availabilityZoneVmTypesMap;
}

@Override
public AvailabilityZones availabilityZones() {
Map<Region, List<AvailabilityZone>> availabiltyZones = new HashMap<>();
for (Region region : regions().types()) {
List<AvailabilityZone> azs = new ArrayList<>();
for (int i = 0; i < 3; i++) {
azs.add(new AvailabilityZone(String.format("%s-zone-%s", region.value(), i)));
}
availabiltyZones.put(region, azs);
}
return new AvailabilityZones(availabiltyZones);
}

@Override
public String resourceDefinition(String resource) {
return "testResourceDefinition";
Expand All @@ -170,20 +88,6 @@ public VmRecommendations recommendedVms() {
return null;
}

@Override
public String getDefaultRegionsConfigString() {
return regionDefinition;
}

public void setDefaultRegionsConfigString(String regionDefinition) {
this.regionDefinition = regionDefinition;
}

@Override
public String getDefaultRegionString() {
return "testRegion-0";
}

@Override
public String platforName() {
return "test";
Expand Down
Loading

0 comments on commit fa8417f

Please sign in to comment.