Search in sources :

Example 16 with InstanceGroupType

use of com.sequenceiq.common.api.type.InstanceGroupType in project cloudbreak by hortonworks.

the class ParameterGenerator method createCloudStack.

public CloudStack createCloudStack() {
    List<Group> groups = new ArrayList<>();
    String name = "master";
    List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1, CloudVolumeUsageType.GENERAL), new Volume("/hadoop/fs2", "HDD", 1, CloudVolumeUsageType.GENERAL));
    InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L, "default-id", TemporaryStorage.ATTACHED_VOLUMES, 0L);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication, "subnet-123", "eu1a");
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    Security security = new Security(rules, emptyList());
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), 50, Optional.empty(), createGroupNetwork(), emptyMap()));
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "redhat6", "", "default", "default-id", new HashMap<>());
    Subnet subnet = new Subnet("10.0.0.0/24");
    Network network = new Network(subnet);
    network.putParameter("publicNetId", "028ffc0c-63c5-4ca0-802a-3ac753eaf76c");
    return new CloudStack(groups, network, image, new HashMap<>(), new HashMap<>(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), null);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 17 with InstanceGroupType

use of com.sequenceiq.common.api.type.InstanceGroupType in project cloudbreak by hortonworks.

the class UserDataService method createUserData.

public void createUserData(Long stackId) throws CloudbreakImageNotFoundException {
    Stack stack = stackService.getByIdWithLists(stackId);
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    Future<PlatformParameters> platformParametersFuture = intermediateBuilderExecutor.submit(() -> connector.getPlatformParameters(stack, userCrn));
    SecurityConfig securityConfig = securityConfigService.generateAndSaveSecurityConfig(stack);
    stack.setSecurityConfig(securityConfig);
    stackService.save(stack);
    SaltSecurityConfig saltSecurityConfig = securityConfig.getSaltSecurityConfig();
    String cbPrivKey = saltSecurityConfig.getSaltBootSignPrivateKey();
    byte[] cbSshKeyDer = PkiUtil.getPublicKeyDer(new String(Base64.decodeBase64(cbPrivKey)));
    String sshUser = stack.getStackAuthentication().getLoginUserName();
    String cbCert = securityConfig.getClientCert();
    String saltBootPassword = saltSecurityConfig.getSaltBootPassword();
    try {
        PlatformParameters platformParameters = platformParametersFuture.get();
        CcmConnectivityParameters ccmParameters = ccmUserDataService.fetchAndSaveCcmParameters(stack);
        Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByEnvironmentCrn(stack.getEnvironmentCrn());
        Map<InstanceGroupType, String> userData = userDataBuilder.buildUserData(Platform.platform(stack.getCloudPlatform()), cbSshKeyDer, sshUser, platformParameters, saltBootPassword, cbCert, ccmParameters, proxyConfig.orElse(null));
        imageService.decorateImageWithUserDataForStack(stack, userData);
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Failed to get Platform parmaters", e);
        throw new GetCloudParameterException("Failed to get Platform parmaters", e);
    }
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with InstanceGroupType

use of com.sequenceiq.common.api.type.InstanceGroupType in project cloudbreak by hortonworks.

the class ClouderaManagerClusterCreationSetupServiceTest method init.

@Before
public void init() throws CloudbreakImageCatalogException {
    MockitoAnnotations.initMocks(this);
    Workspace workspace = new Workspace();
    clusterRequest = new ClusterV4Request();
    stack = new Stack();
    stack.setId(STACK_ID);
    stack.setName("test-stack");
    stack.setWorkspace(workspace);
    Blueprint blueprint = new Blueprint();
    blueprint.setBlueprintText("{}");
    Map<InstanceGroupType, String> userData = new HashMap<>();
    userData.put(InstanceGroupType.CORE, "userdata");
    Image image = new Image("imagename", userData, "centos7", REDHAT_7, "url", IMAGE_CATALOG_NAME, "id", Collections.emptyMap());
    imageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(image), stack);
    cluster = new Cluster();
    stack.setCluster(cluster);
    cluster.setStack(stack);
    cluster.setBlueprint(blueprint);
    cluster.setWorkspace(workspace);
    setupDefaultClouderaManagerEntries();
    Map<String, ImageBasedDefaultCDHInfo> defaultCDHInfoMap = Map.of(OLDER_CDH_VERSION, new ImageBasedDefaultCDHInfo(getDefaultCDHInfo(OLDER_CDH_VERSION), mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class)), SOME_CDH_VERSION, new ImageBasedDefaultCDHInfo(getDefaultCDHInfo(SOME_CDH_VERSION), mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class)), NEWER_CDH_VERSION, new ImageBasedDefaultCDHInfo(getDefaultCDHInfo(NEWER_CDH_VERSION), mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class)));
    when(imageBasedDefaultCDHEntries.getEntries(workspace.getId(), null, IMAGE_CATALOG_NAME)).thenReturn(defaultCDHInfoMap);
    StackMatrixV4Response stackMatrixV4Response = new StackMatrixV4Response();
    stackMatrixV4Response.setCdh(Collections.singletonMap(OLDER_CDH_VERSION, null));
    when(stackMatrixService.getStackMatrix(Mockito.eq(workspace.getId()), Mockito.eq(null), Mockito.anyString())).thenReturn(stackMatrixV4Response);
    when(platformStringTransformer.getPlatformStringForImageCatalog(anyString(), anyString())).thenReturn(imageCatalogPlatform("AWS"));
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ImageBasedDefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) Component(com.sequenceiq.cloudbreak.domain.stack.Component) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) StackMatrixV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Before(org.junit.Before)

Example 19 with InstanceGroupType

use of com.sequenceiq.common.api.type.InstanceGroupType in project cloudbreak by hortonworks.

the class JsonTest method testMultipleSerialisationWithOtherConstructorOfImage.

@Test
public void testMultipleSerialisationWithOtherConstructorOfImage() throws IOException {
    Map<InstanceGroupType, String> userData = new EnumMap<>(InstanceGroupType.class);
    userData.put(InstanceGroupType.CORE, "CORE");
    Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "redhat6", "", "default", "default-id", new HashMap<>());
    Json json = new Json(image);
    String expected = json.getValue();
    Image covertedAgain = json.get(Image.class);
    json = new Json(covertedAgain);
    Assert.assertEquals(expected, json.getValue());
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.Image) EnumMap(java.util.EnumMap) Test(org.junit.Test)

Example 20 with InstanceGroupType

use of com.sequenceiq.common.api.type.InstanceGroupType in project cloudbreak by hortonworks.

the class SecurityAccessManifester method overrideSecurityAccess.

public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) {
    instanceGroups.stream().filter(ig -> ig.getType() == instanceGroupType).forEach(ig -> {
        SecurityGroupV4Request securityGroup = ig.getSecurityGroup();
        if (securityGroup == null) {
            securityGroup = new SecurityGroupV4Request();
        }
        if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) {
            if (!Strings.isNullOrEmpty(securityGroupId)) {
                securityGroup.setSecurityGroupIds(getSecurityGroupIds(securityGroupId));
                securityGroup.setSecurityRules(new ArrayList<>());
            } else if (!Strings.isNullOrEmpty(cidrs)) {
                List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>();
                List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules();
                for (String cidr : CidrUtil.cidrs(cidrs)) {
                    SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr);
                }
                // Because of YCLOUD we should not set this if null
                if (originalSecurityRules != null) {
                    securityGroup.setSecurityRules(generatedSecurityRules);
                }
                securityGroup.setSecurityGroupIds(new HashSet<>());
            } else {
                securityGroup.setSecurityGroupIds(new HashSet<>());
                securityGroup.setSecurityRules(new ArrayList<>());
            }
        }
    });
}
Also used : SecurityRuleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request) SecurityGroupSeparator.getSecurityGroupIds(com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds) ArrayList(java.util.ArrayList) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) List(java.util.List) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) CidrUtil(com.sequenceiq.cloudbreak.util.CidrUtil) Service(org.springframework.stereotype.Service) SecurityRuleUtil(com.sequenceiq.cloudbreak.api.endpoint.v4.util.SecurityRuleUtil) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)31 Image (com.sequenceiq.cloudbreak.cloud.model.Image)17 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)10 HashMap (java.util.HashMap)10 Test (org.junit.Test)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 Network (com.sequenceiq.cloudbreak.cloud.model.Network)8 Security (com.sequenceiq.cloudbreak.cloud.model.Security)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 CcmConnectivityParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters)7 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)7 Group (com.sequenceiq.cloudbreak.cloud.model.Group)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)5 Json (com.sequenceiq.cloudbreak.common.json.Json)5 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)4 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)4 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)4 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)4 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)4