CommonClusterExpandPolicy { public static void expandGroupInstanceType(NodeGroupEntity ngEntity, NodeGroupCreate group, Set<String> sharedPattern, Set<String> localPattern, SoftwareManager softwareManager) { logger.debug("Expand instance type config for group " + ngEntity.getName()); InstanceType instanceType = ngEntity.getNodeType(); int memory = ngEntity.getMemorySize(); int cpu = ngEntity.getCpuNum(); if (instanceType == null && (cpu == 0 || memory == 0)) { throw ClusterConfigException.INSTANCE_SIZE_NOT_SET(group.getName()); } if (instanceType == null) { logger.debug("instance type is not set."); if (softwareManager.hasMgmtRole(group.getRoles())) { instanceType = InstanceType.MEDIUM; } else { instanceType = InstanceType.SMALL; } ngEntity.setNodeType(instanceType); } else { logger.debug("instance type is " + instanceType.toString()); } if (group.getStorage().getSizeGB() <= 0) { GroupType groupType = null; if (softwareManager.hasMgmtRole(group.getRoles())) { groupType = GroupType.MANAGEMENTGROUP; } else { groupType = GroupType.WORKGROUP; } ngEntity.setStorageSize(ExpandUtils.getStorage(instanceType, groupType)); logger.debug("CommonClusterExpandPolicy::expandGroupInstanceType:storage size is setting to default value: " + ngEntity.getStorageSize()); } else { ngEntity.setStorageSize(group.getStorage().getSizeGB()); } if (memory == 0) { ngEntity.setMemorySize(instanceType.getMemoryMB()); } if (cpu == 0) { ngEntity.setCpuNum(instanceType.getCpuNum()); } logger.debug("storage size is set to : " + ngEntity.getStorageSize()); if (ngEntity.getStorageType() == null) { DatastoreType storeType = null; if (softwareManager.hasMgmtRole(group.getRoles())) { if (group.getRoles().contains( HadoopRole.MAPR_FILESERVER_ROLE.toString())) { storeType = DatastoreType.LOCAL; } else { storeType = DatastoreType.SHARED; } } else { storeType = DatastoreType.LOCAL; } if ((sharedPattern == null || sharedPattern.isEmpty()) && DatastoreType.SHARED == storeType) { storeType = DatastoreType.LOCAL; } if ((localPattern == null || localPattern.isEmpty()) && DatastoreType.LOCAL == storeType) { storeType = DatastoreType.SHARED; } ngEntity.setStorageType(storeType); } else { if ((sharedPattern == null || sharedPattern.isEmpty()) && (ngEntity.getStorageType().equals(DatastoreType.SHARED))) { String msg = "Group " + ngEntity.getName() + " is type SHARED, but there are no shared datastore in Serengeti."; logger.error(msg); throw ClusterConfigException.CLUSTER_CONFIG_DATASTORE_TYPE_NONEXISTENT(msg); } if ((localPattern == null || localPattern.isEmpty()) && (ngEntity.getStorageType().equals(DatastoreType.LOCAL))) { String msg = "Group " + ngEntity.getName() + "'s type is LOCAL, but no local datastore in serengeti."; logger.error(msg); throw ClusterConfigException.CLUSTER_CONFIG_DATASTORE_TYPE_NONEXISTENT(msg); } } }  static void expandGroupInstanceType(NodeGroupEntity ngEntity, NodeGroupCreate group,
         Set<String> sharedPattern, Set<String> localPattern, SoftwareManager softwareManager); static void expandDistro(ClusterCreate clusterConfig,
         IronfanStack stack);  }
@Test(groups = { "TestCommonClusterExpandPolicy" }) public void testExpandGroupInstanceType() { List<String> roles = new ArrayList<String>(); roles.add(HadoopRole.HADOOP_RESOURCEMANAGER_ROLE.toString()); NodeGroupCreate nodeGroupCreate = new NodeGroupCreate(); nodeGroupCreate.setName("resourceManager"); nodeGroupCreate.setRoles(roles); nodeGroupCreate.setStorage(new StorageRead()); nodeGroupCreate.setCpuNum(Integer.valueOf(2)); nodeGroupCreate.setMemCapacityMB(Integer.valueOf(3748)); NodeGroupEntity nodeGroupEntity = new NodeGroupEntity(); nodeGroupEntity.setName(nodeGroupCreate.getName()); nodeGroupEntity.setCpuNum(nodeGroupCreate.getCpuNum()); nodeGroupEntity.setMemorySize(nodeGroupCreate.getMemCapacityMB()); CommonClusterExpandPolicy.expandGroupInstanceType(nodeGroupEntity, nodeGroupCreate, null, null, softwareManager); assertEquals(nodeGroupEntity.getNodeType(), InstanceType.MEDIUM); assertEquals(nodeGroupEntity.getStorageSize(), 50); }