Cluster cluster;
try {
cluster = clusters.getCluster(request.getClusterName());
} catch (ClusterNotFoundException e) {
throw new ParentObjectNotFoundException(
"Attempted to add a component to a cluster which doesn't exist:", e);
}
if (request.getServiceName() == null
|| request.getServiceName().isEmpty()) {
StackId stackId = cluster.getDesiredStackVersion();
String serviceName =
ambariMetaInfo.getComponentToService(stackId.getStackName(),
stackId.getStackVersion(), request.getComponentName());
if (LOG.isDebugEnabled()) {
LOG.debug("Looking up service name for component"
+ ", componentName=" + request.getComponentName()
+ ", serviceName=" + serviceName);
}
if (serviceName == null
|| serviceName.isEmpty()) {
throw new AmbariException("Could not find service for component"
+ ", componentName=" + request.getComponentName()
+ ", clusterName=" + cluster.getClusterName()
+ ", stackInfo=" + stackId.getStackId());
}
request.setServiceName(serviceName);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Received a createComponent request"
+ ", clusterName=" + request.getClusterName()
+ ", serviceName=" + request.getServiceName()
+ ", componentName=" + request.getComponentName()
+ ", request=" + request);
}
if (!componentNames.containsKey(request.getClusterName())) {
componentNames.put(request.getClusterName(),
new HashMap<String, Set<String>>());
}
if (!componentNames.get(request.getClusterName())
.containsKey(request.getServiceName())) {
componentNames.get(request.getClusterName()).put(
request.getServiceName(), new HashSet<String>());
}
if (componentNames.get(request.getClusterName())
.get(request.getServiceName()).contains(request.getComponentName())) {
// throw error later for dup
duplicates.add("[clusterName=" + request.getClusterName() + ", serviceName=" + request.getServiceName() +
", componentName=" + request.getComponentName() + "]");
continue;
}
componentNames.get(request.getClusterName())
.get(request.getServiceName()).add(request.getComponentName());
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 ParentObjectNotFoundException(
"Attempted to add a component to a service which doesn't exist:", e);
}
try {
ServiceComponent sc = s.getServiceComponent(request.getComponentName());
if (sc != null) {