ClusterCreate implements Serializable { public void verifyClusterNameLength() { final int MAX_VC_OBJECT_NAME_LENGTH = 80; final int MAX_VM_INDEX_LENGTH = 4; final int VM_LINK_SYMBOL_LENGTH = 2; final int RP_LINK_SYMBOL_LENGTH = 1; int clusterNameLength = getName().length(); int maxNodeGroupNameLength = 0; if (getNodeGroups() == null || getNodeGroups().length == 0) { maxNodeGroupNameLength = 6; } else { int nodeGroupNameLength = 0; for (NodeGroupCreate nodeGroup : this.getNodeGroups()) { nodeGroupNameLength = nodeGroup.getName().length(); if (maxNodeGroupNameLength < nodeGroupNameLength) { maxNodeGroupNameLength = nodeGroupNameLength; } } } int rpNeedLength = MAX_VC_OBJECT_NAME_LENGTH - ConfigInfo.getSerengetiUUID().length() - RP_LINK_SYMBOL_LENGTH; if (rpNeedLength <= 0) { throw ClusterConfigException.UUID_TOO_LONG(MAX_VC_OBJECT_NAME_LENGTH - RP_LINK_SYMBOL_LENGTH); } int vmNeedLength = MAX_VC_OBJECT_NAME_LENGTH - MAX_VM_INDEX_LENGTH - VM_LINK_SYMBOL_LENGTH - maxNodeGroupNameLength; if (vmNeedLength <= 0) { throw ClusterConfigException .NODE_GROUP_NAME_TOO_LONG(MAX_VC_OBJECT_NAME_LENGTH - MAX_VM_INDEX_LENGTH - VM_LINK_SYMBOL_LENGTH); } int clusterNameMaxLength = vmNeedLength - rpNeedLength > 0 ? rpNeedLength : vmNeedLength; if (clusterNameMaxLength < clusterNameLength) { throw ClusterConfigException .CLUSTER_NAME_TOO_LONG(clusterNameMaxLength); } } ClusterCreate();  ClusterCreate(ClusterCreate cluster); @JsonProperty("infrastructure_config") Map<String, Map<String, String>> getInfrastructure_config(); void setInfrastructure_config(Map<String, Map<String, String>> infrastructure_config); Map<String, Object> getConfiguration(); void setConfiguration(Map<String, Object> configuration); @RestRequired String getName(); void setName(String name); String getAppManager(); void setAppManager(String appManager); ClusterType getType(); void setType(ClusterType type); void setExternalHDFS(String externalHDFS); String getExternalHDFS(); String getExternalMapReduce(); void setExternalMapReduce(String externalMapReduce); String getExternalNamenode(); void setExternalNamenode(String externalNamenode); String getExternalSecondaryNamenode(); void setExternalSecondaryNamenode(String externalSecondaryNamenode); Set<String> getExternalDatanodes(); void setExternalDatanodes(Set<String> externalDatanodes); String getDistro(); void setDistro(String distro); @RestIgnore String getDistroVendor(); void setDistroVendor(String distroVendor); @RestIgnore String getDistroVersion(); void setDistroVersion(String distroVersion); String getPackagesExistStatus(); void setPackagesExistStatus(String packagesExistStatus); @RestIgnore String getHttpProxy(); void setHttpProxy(String httpProxy); @RestIgnore String getNoProxy(); void setNoProxy(String noProxy); List<String> getRpNames(); void setRpNames(List<String> rpNames); NodeGroupCreate[] getNodeGroups(); void setNodeGroups(NodeGroupCreate[] nodeGroups); List<String> getDsNames(); void setDsNames(List<String> dsNames); @JsonIgnore List<String> getNetworkNames(); Map<NetTrafficType, List<String>> getNetworkConfig(); void setNetworkConfig(Map<NetTrafficType, List<String>> networkConfig); @RestIgnore List<NetworkAdd> getNetworkings(); void setNetworkings(List<NetworkAdd> networkings); @RestIgnore List<VcCluster> getVcClusters(); void setVcClusters(List<VcCluster> vcClusters); String getTemplateName(); void setTemplateName(String templateName); @RestIgnore List<String> getPackageRepos(); void setPackageRepos(List<String> packageRepos); @RestIgnore HadoopDistroMap getDistroMap(); void setDistroMap(HadoopDistroMap distroMap); TopologyType getTopologyPolicy(); void setTopologyPolicy(TopologyType topologyPolicy); @RestIgnore Map<String, String> getHostToRackMap(); void setHostToRackMap(Map<String, String> hostToRackMap); @RestIgnore Set<String> getSharedDatastorePattern(); void setSharedDatastorePattern(Set<String> sharedDatastorePattern); @RestIgnore Set<String> getLocalDatastorePattern(); void setLocalDatastorePattern(Set<String> localDatastorePattern); Boolean isValidateConfig(); void setValidateConfig(Boolean validateConfig); @RestIgnore String getDeployPolicy(); void setDeployPolicy(String deployPolicy); Boolean isSpecFile(); void setSpecFile(Boolean specFile); boolean validateNodeGroupPlacementPolicies(
         List<String> failedMsgList, List<String> warningMsgList); void validateStorageType(List<String> failedMsgList); boolean hasHDFSUrlConfigured(); boolean validateHDFSUrl(); int totalInstances(); NodeGroupCreate getNodeGroup(String name); void validateClusterCreate(List<String> failedMsgList,
         List<String> warningMsgList); boolean supportedWithHdfs2(); void validateCDHVersion(List<String> warningMsgList); void validateNodeGroupNames(); String getPassword(); void setPassword(String password); void verifyClusterNameLength(); ClusterBlueprint toBlueprint(); String getLocalRepoURL(); void setLocalRepoURL(String localRepoURL); String getHostnamePrefix(); void setHostnamePrefix(String hostnamePrefix); String getClusterCloneType(); void setClusterCloneType(String clusterCloneType);  }
@Test public void testVerifyClusterNameLength() { boolean failed = false; ClusterCreate cluster = new ClusterCreate(); cluster.setName("Test"); cluster.verifyClusterNameLength(); ConfigInfo.setSerengetiUUID("Serengeti.uuid"); cluster .setName("Test1234567890123456789012345678901234567890123456789012345678901234"); try { cluster.verifyClusterNameLength(); } catch (ClusterConfigException e) { assertEquals(e.getMessage(), "The length of the cluster name must be equal or less than 65."); failed = true; } assertTrue(failed); failed = false; cluster .setName("Test1234567890123456789012345678901234567890123456789012345678901234"); NodeGroupCreate resourceManager = new NodeGroupCreate(); resourceManager.setName("resourceManager"); NodeGroupCreate zookeeper = new NodeGroupCreate(); zookeeper.setName("zookeeper"); cluster .setNodeGroups(new NodeGroupCreate[] { resourceManager, zookeeper }); try { cluster.verifyClusterNameLength(); } catch (ClusterConfigException e) { assertEquals(e.getMessage(), "The length of the cluster name must be equal or less than 59."); failed = true; } assertTrue(failed); failed = false; NodeGroupCreate otherNodeGroup = new NodeGroupCreate(); otherNodeGroup .setName("NodeGroup12345678901234567890123456789012345678901234567890123456789012345"); cluster.setNodeGroups(new NodeGroupCreate[] { otherNodeGroup }); try { cluster.verifyClusterNameLength(); } catch (ClusterConfigException e) { assertEquals(e.getMessage(), "The length of the node group name must be less than 74."); failed = true; } assertTrue(failed); }