Cluster cluster;
try {
cluster = clusters.getCluster(request.getClusterName());
} catch (ClusterNotFoundException e) {
throw new ParentObjectNotFoundException(
"Attempted to add a host_component to a cluster which doesn't exist: ", e);
}
if (StringUtils.isEmpty(request.getServiceName())) {
request.setServiceName(findServiceName(cluster, request.getComponentName()));
}
if (LOG.isDebugEnabled()) {
LOG.debug("Received a createHostComponent request"
+ ", clusterName=" + request.getClusterName()
+ ", serviceName=" + request.getServiceName()
+ ", componentName=" + request.getComponentName()
+ ", hostname=" + request.getHostname()
+ ", request=" + request);
}
if (!hostComponentNames.containsKey(request.getClusterName())) {
hostComponentNames.put(request.getClusterName(),
new HashMap<String, Map<String,Set<String>>>());
}
if (!hostComponentNames.get(request.getClusterName())
.containsKey(request.getServiceName())) {
hostComponentNames.get(request.getClusterName()).put(
request.getServiceName(), new HashMap<String, Set<String>>());
}
if (!hostComponentNames.get(request.getClusterName())
.get(request.getServiceName())
.containsKey(request.getComponentName())) {
hostComponentNames.get(request.getClusterName())
.get(request.getServiceName()).put(request.getComponentName(),
new HashSet<String>());
}
if (hostComponentNames.get(request.getClusterName())
.get(request.getServiceName()).get(request.getComponentName())
.contains(request.getHostname())) {
duplicates.add("[clusterName=" + request.getClusterName() + ", hostName=" + request.getHostname() +
", componentName=" +request.getComponentName() +']');
continue;
}
hostComponentNames.get(request.getClusterName())
.get(request.getServiceName()).get(request.getComponentName())
.add(request.getHostname());
if (request.getDesiredState() != null
&& !request.getDesiredState().isEmpty()) {
State state = State.valueOf(request.getDesiredState());
if (!state.isValidDesiredState()
|| state != State.INIT) {
throw new IllegalArgumentException("Invalid desired state"
+ " only INIT state allowed during creation"
+ ", providedDesiredState=" + request.getDesiredState());
}
}
Service s;
try {
s = cluster.getService(request.getServiceName());
} catch (ServiceNotFoundException e) {
throw new IllegalArgumentException(
"The service[" + request.getServiceName() + "] associated with the component[" +
request.getComponentName() + "] doesn't exist for the cluster[" + request.getClusterName() + "]");
}
ServiceComponent sc = s.getServiceComponent(
request.getComponentName());
Host host;
try {
host = clusters.getHost(request.getHostname());
} catch (HostNotFoundException e) {
throw new ParentObjectNotFoundException(
"Attempted to add a host_component to a host that doesn't exist: ", e);
}
Set<Cluster> mappedClusters =
clusters.getClustersForHost(request.getHostname());
boolean validCluster = false;
if (LOG.isDebugEnabled()) {
LOG.debug("Looking to match host to cluster"
+ ", hostnameViaReg=" + host.getHostName()
+ ", hostname=" + request.getHostname()
+ ", clusterName=" + request.getClusterName()
+ ", hostClusterMapCount=" + mappedClusters.size());
}
for (Cluster mappedCluster : mappedClusters) {
if (LOG.isDebugEnabled()) {
LOG.debug("Host belongs to cluster"
+ ", hostname=" + request.getHostname()
+ ", clusterName=" + mappedCluster.getClusterName());
}
if (mappedCluster.getClusterName().equals(
request.getClusterName())) {
validCluster = true;
break;
}
}
if (!validCluster) {
throw new ParentObjectNotFoundException("Attempted to add a host_component to a host that doesn't exist: " +
"clusterName=" + request.getClusterName() + ", hostName=" + request.getHostname());
}
try {
ServiceComponentHost sch = sc.getServiceComponentHost(
request.getHostname());