} catch (ObjectNotFoundException e) {
throw new ParentObjectNotFoundException("Parent Service resource doesn't exist", e);
}
ServiceComponent sc = s.getServiceComponent(request.getComponentName());
ServiceComponentResponse serviceComponentResponse = sc.convertToResponse();
ComponentInfo componentInfo = ambariMetaInfo.getComponentCategory(stackId.getStackName(),
stackId.getStackVersion(), s.getName(), request.getComponentName());
if (componentInfo != null) {
category = componentInfo.getCategory();
if (category != null) {
serviceComponentResponse.setCategory(category);
}
}
response.add(serviceComponentResponse);
return response;
}
boolean checkDesiredState = false;
State desiredStateToCheck = null;
if (request.getDesiredState() != null
&& !request.getDesiredState().isEmpty()) {
desiredStateToCheck = State.valueOf(request.getDesiredState());
if (!desiredStateToCheck.isValidDesiredState()) {
throw new IllegalArgumentException("Invalid arguments, invalid desired"
+ " state, desiredState=" + desiredStateToCheck);
}
checkDesiredState = true;
}
Set<Service> services = new HashSet<Service>();
if (request.getServiceName() != null
&& !request.getServiceName().isEmpty()) {
try {
services.add(cluster.getService(request.getServiceName()));
} catch (ObjectNotFoundException e) {
throw new ParentObjectNotFoundException("Could not find service", e);
}
} else {
services.addAll(cluster.getServices().values());
}
for (Service s : services) {
// filter on request.getDesiredState()
for (ServiceComponent sc : s.getServiceComponents().values()) {
if (checkDesiredState
&& (desiredStateToCheck != sc.getDesiredState())) {
// skip non matching state
continue;
}
ComponentInfo componentInfo = ambariMetaInfo.getComponentCategory(stackId.getStackName(),
stackId.getStackVersion(), s.getName(), sc.getName());
ServiceComponentResponse serviceComponentResponse = sc.convertToResponse();
String requestedCategory = request.getComponentCategory();
if (componentInfo != null) {
category = componentInfo.getCategory();
if (category != null) {
serviceComponentResponse.setCategory(category);
}
}
if (requestedCategory != null && !requestedCategory.isEmpty() &&
category != null && !requestedCategory.equalsIgnoreCase(category)) {
continue;