id
stringlengths 7
14
| text
stringlengths 1
106k
|
---|---|
223551095_1372 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<Resource> resources = new HashSet<>();
final Set<String> requestedIds = getRequestPropertyIds(request, predicate);
final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
List<WidgetEntity> widgetEntities = new ArrayList<>();
List<WidgetLayoutEntity> layoutEntities = new ArrayList<>();
for (Map<String, Object> propertyMap: propertyMaps) {
String userName = getUserName(propertyMap);
if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) {
final Long id;
try {
id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString());
} catch (Exception ex) {
throw new SystemException("WidgetLayout should have numerical id");
}
final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id);
if (entity == null) {
throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists");
}
layoutEntities.add(entity);
} else {
layoutEntities.addAll(widgetLayoutDAO.findAll());
}
}
for (WidgetLayoutEntity layoutEntity : layoutEntities) {
Resource resource = new ResourceImpl(Type.WidgetLayout);
resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId());
String clusterName = null;
try {
clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName();
} catch (AmbariException e) {
throw new SystemException(e.getMessage());
}
resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName);
resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName());
resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName());
resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope());
resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName());
resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName());
List<HashMap> widgets = new ArrayList<>();
List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity();
for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) {
WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget();
HashMap<String, Object> widgetInfoMap = new HashMap<>();
widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity));
widgets.add(widgetInfoMap);
}
resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets);
resources.add(resource);
}
return resources;
} |
223551095_1373 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<Resource> resources = new HashSet<>();
final Set<String> requestedIds = getRequestPropertyIds(request, predicate);
final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
List<WidgetEntity> widgetEntities = new ArrayList<>();
List<WidgetLayoutEntity> layoutEntities = new ArrayList<>();
for (Map<String, Object> propertyMap: propertyMaps) {
String userName = getUserName(propertyMap);
if (propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID) != null) {
final Long id;
try {
id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString());
} catch (Exception ex) {
throw new SystemException("WidgetLayout should have numerical id");
}
final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id);
if (entity == null) {
throw new NoSuchResourceException("WidgetLayout with id " + id + " does not exists");
}
layoutEntities.add(entity);
} else {
layoutEntities.addAll(widgetLayoutDAO.findAll());
}
}
for (WidgetLayoutEntity layoutEntity : layoutEntities) {
Resource resource = new ResourceImpl(Type.WidgetLayout);
resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, layoutEntity.getId());
String clusterName = null;
try {
clusterName = getManagementController().getClusters().getClusterById(layoutEntity.getClusterId()).getClusterName();
} catch (AmbariException e) {
throw new SystemException(e.getMessage());
}
resource.setProperty(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID, clusterName);
resource.setProperty(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, layoutEntity.getLayoutName());
resource.setProperty(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID, layoutEntity.getSectionName());
resource.setProperty(WIDGETLAYOUT_SCOPE_PROPERTY_ID, layoutEntity.getScope());
resource.setProperty(WIDGETLAYOUT_USERNAME_PROPERTY_ID, layoutEntity.getUserName());
resource.setProperty(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID, layoutEntity.getDisplayName());
List<HashMap> widgets = new ArrayList<>();
List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = layoutEntity.getListWidgetLayoutUserWidgetEntity();
for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : widgetLayoutUserWidgetEntityList) {
WidgetEntity widgetEntity = widgetLayoutUserWidgetEntity.getWidget();
HashMap<String, Object> widgetInfoMap = new HashMap<>();
widgetInfoMap.put("WidgetInfo",WidgetResponse.coerce(widgetEntity));
widgets.add(widgetInfoMap);
}
resource.setProperty(WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgets);
resources.add(resource);
}
return resources;
} |
223551095_1374 | @Override
public RequestStatus createResources(final Request request)
throws SystemException,
UnsupportedPropertyException,
ResourceAlreadyExistsException,
NoSuchParentResourceException {
Set<Resource> associatedResources = new HashSet<>();
for (final Map<String, Object> properties : request.getProperties()) {
WidgetLayoutEntity widgetLayoutEntity = createResources(new Command<WidgetLayoutEntity>() {
@Override
public WidgetLayoutEntity invoke() throws AmbariException {
final String[] requiredProperties = {
WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID,
WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID,
WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID,
WIDGETLAYOUT_SCOPE_PROPERTY_ID,
WIDGETLAYOUT_WIDGETS_PROPERTY_ID,
WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID,
WIDGETLAYOUT_USERNAME_PROPERTY_ID
};
for (String propertyName : requiredProperties) {
if (properties.get(propertyName) == null) {
throw new AmbariException("Property " + propertyName + " should be provided");
}
}
final WidgetLayoutEntity entity = new WidgetLayoutEntity();
String userName = getUserName(properties);
Set widgetsSet = (LinkedHashSet) properties.get(WIDGETLAYOUT_WIDGETS_PROPERTY_ID);
String clusterName = properties.get(WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID).toString();
entity.setLayoutName(properties.get(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID).toString());
entity.setClusterId(getManagementController().getClusters().getCluster(clusterName).getClusterId());
entity.setSectionName(properties.get(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID).toString());
entity.setScope(properties.get(WIDGETLAYOUT_SCOPE_PROPERTY_ID).toString());
entity.setUserName(userName);
entity.setDisplayName(properties.get(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID).toString());
List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = new LinkedList<>();
int order=0;
for (Object widgetObject : widgetsSet) {
HashMap<String, Object> widget = (HashMap) widgetObject;
long id = Integer.parseInt(widget.get("id").toString());
WidgetEntity widgetEntity = widgetDAO.findById(id);
if (widgetEntity == null) {
throw new AmbariException("Widget with id " + widget.get("id") + " does not exists");
}
WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity = new WidgetLayoutUserWidgetEntity();
widgetLayoutUserWidgetEntity.setWidget(widgetEntity);
widgetLayoutUserWidgetEntity.setWidgetOrder(order++);
widgetLayoutUserWidgetEntity.setWidgetLayout(entity);
widgetLayoutUserWidgetEntityList.add(widgetLayoutUserWidgetEntity);
widgetEntity.getListWidgetLayoutUserWidgetEntity().add(widgetLayoutUserWidgetEntity);
}
entity.setListWidgetLayoutUserWidgetEntity(widgetLayoutUserWidgetEntityList);
widgetLayoutDAO.create(entity);
notifyCreate(Type.WidgetLayout, request);
return entity;
}
});
Resource resource = new ResourceImpl(Type.WidgetLayout);
resource.setProperty(WIDGETLAYOUT_ID_PROPERTY_ID, widgetLayoutEntity.getId());
associatedResources.add(resource);
}
return getRequestStatus(null, associatedResources);
} |
223551095_1375 | @Override
public RequestStatus updateResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<Map<String, Object>> propertyMaps = request.getProperties();
modifyResources(new Command<Void>() {
@Override
public Void invoke() throws AmbariException {
for (Map<String, Object> propertyMap : propertyMaps) {
final Long layoutId;
try {
layoutId = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString());
} catch (Exception ex) {
throw new AmbariException("WidgetLayout should have numerical id");
}
lock.writeLock().lock();
try {
final WidgetLayoutEntity entity = widgetLayoutDAO.findById(layoutId);
if (entity == null) {
throw new ObjectNotFoundException("There is no widget layout with id " + layoutId);
}
if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID)))) {
entity.setLayoutName(propertyMap.get(WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID).toString());
}
if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID)))) {
entity.setSectionName(propertyMap.get(WIDGETLAYOUT_SECTION_NAME_PROPERTY_ID).toString());
}
if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID)))) {
entity.setDisplayName(propertyMap.get(WIDGETLAYOUT_DISPLAY_NAME_PROPERTY_ID).toString());
}
if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(WIDGETLAYOUT_SCOPE_PROPERTY_ID)))) {
entity.setScope(propertyMap.get(WIDGETLAYOUT_SCOPE_PROPERTY_ID).toString());
}
Set widgetsSet = (LinkedHashSet) propertyMap.get(WIDGETLAYOUT_WIDGETS_PROPERTY_ID);
//Remove old relations from widget entities
for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : entity.getListWidgetLayoutUserWidgetEntity()) {
widgetLayoutUserWidgetEntity.getWidget().getListWidgetLayoutUserWidgetEntity()
.remove(widgetLayoutUserWidgetEntity);
}
entity.setListWidgetLayoutUserWidgetEntity(new LinkedList<>());
List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = new LinkedList<>();
int order = 0;
for (Object widgetObject : widgetsSet) {
HashMap<String, Object> widget = (HashMap) widgetObject;
long id = Integer.parseInt(widget.get("id").toString());
WidgetEntity widgetEntity = widgetDAO.findById(id);
if (widgetEntity == null) {
throw new AmbariException("Widget with id " + widget.get("id") + " does not exists");
}
WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity = new WidgetLayoutUserWidgetEntity();
widgetLayoutUserWidgetEntity.setWidget(widgetEntity);
widgetLayoutUserWidgetEntity.setWidgetOrder(order++);
widgetLayoutUserWidgetEntity.setWidgetLayout(entity);
widgetLayoutUserWidgetEntityList.add(widgetLayoutUserWidgetEntity);
widgetEntity.getListWidgetLayoutUserWidgetEntity().add(widgetLayoutUserWidgetEntity);
entity.getListWidgetLayoutUserWidgetEntity().add(widgetLayoutUserWidgetEntity);
}
widgetLayoutDAO.mergeWithFlush(entity);
} finally {
lock.writeLock().unlock();
}
}
return null;
}
});
return getRequestStatus(null);
} |
223551095_1376 | @Override
public RequestStatus deleteResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
final List<WidgetLayoutEntity> entitiesToBeRemoved = new ArrayList<>();
for (Map<String, Object> propertyMap : propertyMaps) {
final Long id;
try {
id = Long.parseLong(propertyMap.get(WIDGETLAYOUT_ID_PROPERTY_ID).toString());
} catch (Exception ex) {
throw new SystemException("WidgetLayout should have numerical id");
}
final WidgetLayoutEntity entity = widgetLayoutDAO.findById(id);
if (entity == null) {
throw new NoSuchResourceException("There is no widget layout with id " + id);
}
entitiesToBeRemoved.add(entity);
}
for (WidgetLayoutEntity entity: entitiesToBeRemoved) {
if (entity.getListWidgetLayoutUserWidgetEntity() != null) {
for (WidgetLayoutUserWidgetEntity layoutUserWidgetEntity : entity.getListWidgetLayoutUserWidgetEntity()) {
if (layoutUserWidgetEntity.getWidget().getListWidgetLayoutUserWidgetEntity() != null) {
layoutUserWidgetEntity.getWidget().getListWidgetLayoutUserWidgetEntity().remove(layoutUserWidgetEntity);
}
}
}
widgetLayoutDAO.remove(entity);
}
return getRequestStatus(null);
} |
223551095_1377 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
ViewRegistry viewRegistry = ViewRegistry.getInstance();
Set<Resource> resources = new HashSet<>();
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission();
for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) {
Object viewName = propertyMap.get(VIEW_NAME);
Object viewVersion = propertyMap.get(VERSION);
if (viewName != null && viewVersion != null) {
ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString());
// do not report permissions for views that are not loaded.
if (viewEntity.isDeployed()) {
ViewPermissionResponse viewPermissionResponse = getResponse(viewUsePermission, viewEntity.getResourceType(), viewEntity);
resources.add(toResource(viewPermissionResponse, requestedIds));
}
}
}
for(PermissionEntity permissionEntity : permissionDAO.findAll()){
ResourceTypeEntity resourceType = permissionEntity.getResourceType();
ViewEntity viewEntity = viewRegistry.getDefinition(resourceType);
if (viewEntity != null && viewEntity.isDeployed()) {
ViewPermissionResponse viewPermissionResponse = getResponse(permissionEntity, resourceType, viewEntity);
resources.add(toResource(viewPermissionResponse, requestedIds));
}
}
return resources;
} |
223551095_1378 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
ViewRegistry viewRegistry = ViewRegistry.getInstance();
Set<Resource> resources = new HashSet<>();
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
PermissionEntity viewUsePermission = permissionDAO.findViewUsePermission();
for (Map<String, Object> propertyMap: getPropertyMaps(predicate)) {
Object viewName = propertyMap.get(VIEW_NAME);
Object viewVersion = propertyMap.get(VERSION);
if (viewName != null && viewVersion != null) {
ViewEntity viewEntity = viewRegistry.getDefinition(viewName.toString(), viewVersion.toString());
// do not report permissions for views that are not loaded.
if (viewEntity.isDeployed()) {
ViewPermissionResponse viewPermissionResponse = getResponse(viewUsePermission, viewEntity.getResourceType(), viewEntity);
resources.add(toResource(viewPermissionResponse, requestedIds));
}
}
}
for(PermissionEntity permissionEntity : permissionDAO.findAll()){
ResourceTypeEntity resourceType = permissionEntity.getResourceType();
ViewEntity viewEntity = viewRegistry.getDefinition(resourceType);
if (viewEntity != null && viewEntity.isDeployed()) {
ViewPermissionResponse viewPermissionResponse = getResponse(permissionEntity, resourceType, viewEntity);
resources.add(toResource(viewPermissionResponse, requestedIds));
}
}
return resources;
} |
223551095_1379 | @Override
public RequestStatus createResources(Request request) {
throw new UnsupportedOperationException("Not currently supported.");
} |
223551095_1380 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = new LinkedHashSet<>();
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
List<HostRoleCommandEntity> entities = s_dao.findAll(request, predicate);
// !!! getting the cluster name out of the request property maps is a little
// hacky since there could be a different request per cluster name; however
// nobody is making task requests across clusters. Overall, this loop could
// be called multiple times when using predicates like
// tasks/Tasks/status.in(FAILED,ABORTED,TIMEDOUT) which would unnecessarily
// make the same call to the API over and over
String clusterName = null;
Long requestId = null;
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
clusterName = (String) propertyMap.get(TASK_CLUSTER_NAME_PROPERTY_ID);
String requestIdStr = (String) propertyMap.get(TASK_REQUEST_ID_PROPERTY_ID);
requestId = Long.parseLong(requestIdStr);
}
Collection<HostRoleCommand> commands = new ArrayList<>(100);
if (!entities.isEmpty()) {
for (HostRoleCommandEntity entity : entities) {
commands.add(s_hostRoleCommandFactory.createExisting(entity));
}
} else {
// if query has no results, look up in TopologyManager as the request might be a TopologyLogicalRequest
// which is not directly linked to tasks
if (requestId != null) {
commands.addAll(s_topologyManager.getTasks(requestId));
}
}
LOG.debug("Retrieved {} commands for request {}", commands.size(), request);
// convert each entity into a response
for (HostRoleCommand hostRoleCommand : commands) {
Resource resource = new ResourceImpl(Resource.Type.Task);
// !!! shocked this isn't broken. the key can be null for non-cluster tasks
if (null != clusterName) {
setResourceProperty(resource, TASK_CLUSTER_NAME_PROPERTY_ID, clusterName, requestedIds);
}
setResourceProperty(resource, TASK_REQUEST_ID_PROPERTY_ID, hostRoleCommand.getRequestId(), requestedIds);
setResourceProperty(resource, TASK_ID_PROPERTY_ID, hostRoleCommand.getTaskId(), requestedIds);
setResourceProperty(resource, TASK_STAGE_ID_PROPERTY_ID, hostRoleCommand.getStageId(), requestedIds);
setResourceProperty(resource, TASK_HOST_NAME_PROPERTY_ID, ensureHostname(hostRoleCommand.getHostName()), requestedIds);
setResourceProperty(resource, TASK_ROLE_PROPERTY_ID, hostRoleCommand.getRole().toString(), requestedIds);
setResourceProperty(resource, TASK_COMMAND_PROPERTY_ID, hostRoleCommand.getRoleCommand(), requestedIds);
setResourceProperty(resource, TASK_STATUS_PROPERTY_ID, hostRoleCommand.getStatus(), requestedIds);
setResourceProperty(resource, TASK_EXIT_CODE_PROPERTY_ID, hostRoleCommand.getExitCode(), requestedIds);
setResourceProperty(resource, TASK_STDERR_PROPERTY_ID, hostRoleCommand.getStderr(), requestedIds);
setResourceProperty(resource, TASK_STOUT_PROPERTY_ID, hostRoleCommand.getStdout(), requestedIds);
setResourceProperty(resource, TASK_OUTPUTLOG_PROPERTY_ID, hostRoleCommand.getOutputLog(), requestedIds);
setResourceProperty(resource, TASK_ERRORLOG_PROPERTY_ID, hostRoleCommand.getErrorLog(), requestedIds);
setResourceProperty(resource, TASK_STRUCT_OUT_PROPERTY_ID, parseStructuredOutput(hostRoleCommand.getStructuredOut()), requestedIds);
setResourceProperty(resource, TASK_START_TIME_PROPERTY_ID, hostRoleCommand.getStartTime(), requestedIds);
setResourceProperty(resource, TASK_END_TIME_PROPERTY_ID, hostRoleCommand.getEndTime(), requestedIds);
setResourceProperty(resource, TASK_ATTEMPT_CNT_PROPERTY_ID, hostRoleCommand.getAttemptCount(), requestedIds);
if (hostRoleCommand.getCustomCommandName() != null) {
setResourceProperty(resource, TASK_CUST_CMD_NAME_PROPERTY_ID, hostRoleCommand.getCustomCommandName(), requestedIds);
}
if (hostRoleCommand.getCommandDetail() == null) {
setResourceProperty(resource, TASK_COMMAND_DET_PROPERTY_ID,
String.format("%s %s", hostRoleCommand.getRole().toString(), hostRoleCommand.getRoleCommand()), requestedIds);
} else {
setResourceProperty(resource, TASK_COMMAND_DET_PROPERTY_ID, hostRoleCommand.getCommandDetail(), requestedIds);
}
setResourceProperty(resource, TASK_COMMAND_OPS_DISPLAY_NAME, hostRoleCommand.getOpsDisplayName(), requestedIds);
results.add(resource);
}
return results;
} |
223551095_1381 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = new LinkedHashSet<>();
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
List<HostRoleCommandEntity> entities = s_dao.findAll(request, predicate);
// !!! getting the cluster name out of the request property maps is a little
// hacky since there could be a different request per cluster name; however
// nobody is making task requests across clusters. Overall, this loop could
// be called multiple times when using predicates like
// tasks/Tasks/status.in(FAILED,ABORTED,TIMEDOUT) which would unnecessarily
// make the same call to the API over and over
String clusterName = null;
Long requestId = null;
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
clusterName = (String) propertyMap.get(TASK_CLUSTER_NAME_PROPERTY_ID);
String requestIdStr = (String) propertyMap.get(TASK_REQUEST_ID_PROPERTY_ID);
requestId = Long.parseLong(requestIdStr);
}
Collection<HostRoleCommand> commands = new ArrayList<>(100);
if (!entities.isEmpty()) {
for (HostRoleCommandEntity entity : entities) {
commands.add(s_hostRoleCommandFactory.createExisting(entity));
}
} else {
// if query has no results, look up in TopologyManager as the request might be a TopologyLogicalRequest
// which is not directly linked to tasks
if (requestId != null) {
commands.addAll(s_topologyManager.getTasks(requestId));
}
}
LOG.debug("Retrieved {} commands for request {}", commands.size(), request);
// convert each entity into a response
for (HostRoleCommand hostRoleCommand : commands) {
Resource resource = new ResourceImpl(Resource.Type.Task);
// !!! shocked this isn't broken. the key can be null for non-cluster tasks
if (null != clusterName) {
setResourceProperty(resource, TASK_CLUSTER_NAME_PROPERTY_ID, clusterName, requestedIds);
}
setResourceProperty(resource, TASK_REQUEST_ID_PROPERTY_ID, hostRoleCommand.getRequestId(), requestedIds);
setResourceProperty(resource, TASK_ID_PROPERTY_ID, hostRoleCommand.getTaskId(), requestedIds);
setResourceProperty(resource, TASK_STAGE_ID_PROPERTY_ID, hostRoleCommand.getStageId(), requestedIds);
setResourceProperty(resource, TASK_HOST_NAME_PROPERTY_ID, ensureHostname(hostRoleCommand.getHostName()), requestedIds);
setResourceProperty(resource, TASK_ROLE_PROPERTY_ID, hostRoleCommand.getRole().toString(), requestedIds);
setResourceProperty(resource, TASK_COMMAND_PROPERTY_ID, hostRoleCommand.getRoleCommand(), requestedIds);
setResourceProperty(resource, TASK_STATUS_PROPERTY_ID, hostRoleCommand.getStatus(), requestedIds);
setResourceProperty(resource, TASK_EXIT_CODE_PROPERTY_ID, hostRoleCommand.getExitCode(), requestedIds);
setResourceProperty(resource, TASK_STDERR_PROPERTY_ID, hostRoleCommand.getStderr(), requestedIds);
setResourceProperty(resource, TASK_STOUT_PROPERTY_ID, hostRoleCommand.getStdout(), requestedIds);
setResourceProperty(resource, TASK_OUTPUTLOG_PROPERTY_ID, hostRoleCommand.getOutputLog(), requestedIds);
setResourceProperty(resource, TASK_ERRORLOG_PROPERTY_ID, hostRoleCommand.getErrorLog(), requestedIds);
setResourceProperty(resource, TASK_STRUCT_OUT_PROPERTY_ID, parseStructuredOutput(hostRoleCommand.getStructuredOut()), requestedIds);
setResourceProperty(resource, TASK_START_TIME_PROPERTY_ID, hostRoleCommand.getStartTime(), requestedIds);
setResourceProperty(resource, TASK_END_TIME_PROPERTY_ID, hostRoleCommand.getEndTime(), requestedIds);
setResourceProperty(resource, TASK_ATTEMPT_CNT_PROPERTY_ID, hostRoleCommand.getAttemptCount(), requestedIds);
if (hostRoleCommand.getCustomCommandName() != null) {
setResourceProperty(resource, TASK_CUST_CMD_NAME_PROPERTY_ID, hostRoleCommand.getCustomCommandName(), requestedIds);
}
if (hostRoleCommand.getCommandDetail() == null) {
setResourceProperty(resource, TASK_COMMAND_DET_PROPERTY_ID,
String.format("%s %s", hostRoleCommand.getRole().toString(), hostRoleCommand.getRoleCommand()), requestedIds);
} else {
setResourceProperty(resource, TASK_COMMAND_DET_PROPERTY_ID, hostRoleCommand.getCommandDetail(), requestedIds);
}
setResourceProperty(resource, TASK_COMMAND_OPS_DISPLAY_NAME, hostRoleCommand.getOpsDisplayName(), requestedIds);
results.add(resource);
}
return results;
} |
223551095_1382 | @Override
public RequestStatus updateResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
throw new UnsupportedOperationException("Not currently supported.");
} |
223551095_1383 | @Override
public RequestStatus deleteResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
throw new UnsupportedOperationException("Not currently supported.");
} |
223551095_1384 | Map<?, ?> parseStructuredOutput(String structuredOutput) {
if (null == structuredOutput || structuredOutput.isEmpty()) {
return null;
}
Map<?, ?> result = null;
try {
result = mapper.readValue(structuredOutput, Map.class);
} catch (Exception excepton) {
LOG.warn("Unable to parse task structured output: {}", structuredOutput);
}
return result;
} |
223551095_1385 | Map<?, ?> parseStructuredOutput(String structuredOutput) {
if (null == structuredOutput || structuredOutput.isEmpty()) {
return null;
}
Map<?, ?> result = null;
try {
result = mapper.readValue(structuredOutput, Map.class);
} catch (Exception excepton) {
LOG.warn("Unable to parse task structured output: {}", structuredOutput);
}
return result;
} |
223551095_1386 | Map<?, ?> parseStructuredOutput(String structuredOutput) {
if (null == structuredOutput || structuredOutput.isEmpty()) {
return null;
}
Map<?, ?> result = null;
try {
result = mapper.readValue(structuredOutput, Map.class);
} catch (Exception excepton) {
LOG.warn("Unable to parse task structured output: {}", structuredOutput);
}
return result;
} |
223551095_1387 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1388 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1389 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1390 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1391 | private ServiceRequest getRequest(Map<String, Object> properties) {
String desiredRepoId = (String) properties.get(SERVICE_DESIRED_REPO_VERSION_ID_PROPERTY_ID);
ServiceRequest svcRequest = new ServiceRequest(
(String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID),
(String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID),
null == desiredRepoId ? null : Long.valueOf(desiredRepoId),
(String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID),
(String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID));
Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID);
if (null != o) {
svcRequest.setMaintenanceState(o.toString());
}
o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID);
if (null != o) {
svcRequest.setCredentialStoreSupported(o.toString());
}
return svcRequest;
} |
223551095_1392 | private ServiceRequest getRequest(Map<String, Object> properties) {
String desiredRepoId = (String) properties.get(SERVICE_DESIRED_REPO_VERSION_ID_PROPERTY_ID);
ServiceRequest svcRequest = new ServiceRequest(
(String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID),
(String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID),
null == desiredRepoId ? null : Long.valueOf(desiredRepoId),
(String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID),
(String) properties.get(SERVICE_CREDENTIAL_STORE_ENABLED_PROPERTY_ID));
Object o = properties.get(SERVICE_MAINTENANCE_STATE_PROPERTY_ID);
if (null != o) {
svcRequest.setMaintenanceState(o.toString());
}
o = properties.get(SERVICE_CREDENTIAL_STORE_SUPPORTED_PROPERTY_ID);
if (null != o) {
svcRequest.setCredentialStoreSupported(o.toString());
}
return svcRequest;
} |
223551095_1393 | @Override
public Set<String> checkPropertyIds(Set<String> propertyIds) {
propertyIds = super.checkPropertyIds(propertyIds);
if (propertyIds.isEmpty()) {
return propertyIds;
}
Set<String> unsupportedProperties = new HashSet<>();
for (String propertyId : propertyIds) {
if (!propertyId.equals("config")) {
String propertyCategory = PropertyHelper.getPropertyCategory(propertyId);
if (propertyCategory == null || !propertyCategory.equals("config")) {
unsupportedProperties.add(propertyId);
}
}
}
return unsupportedProperties;
} |
223551095_1394 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1395 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1396 | protected Set<ServiceResponse> getServices(Set<ServiceRequest> requests)
throws AmbariException {
Set<ServiceResponse> response = new HashSet<>();
for (ServiceRequest request : requests) {
try {
response.addAll(getServices(request));
} catch (ServiceNotFoundException e) {
if (requests.size() == 1) {
// only throw exception if 1 request.
// there will be > 1 request in case of OR predicate
throw e;
}
}
}
return response;
} |
223551095_1398 | @SuppressWarnings("unchecked")
ConfigGroupRequest getConfigGroupRequest(Map<String, Object> properties) {
Object groupIdObj = properties.get(ID);
Long groupId = null;
if (groupIdObj != null) {
groupId = groupIdObj instanceof Long ? (Long) groupIdObj :
Long.parseLong((String) groupIdObj);
}
ConfigGroupRequest request = new ConfigGroupRequest(
groupId,
(String) properties.get(CLUSTER_NAME),
(String) properties.get(GROUP_NAME),
(String) properties.get(TAG),
(String) properties.get(SERVICE_NAME),
(String) properties.get(DESCRIPTION),
null,
null);
request.setServiceConfigVersionNote((String) properties.get(SERVICE_CONFIG_VERSION_NOTE));
Map<String, Config> configurations = new HashMap<>();
Set<String> hosts = new HashSet<>();
String hostnameKey = HOST_NAME;
Object hostObj = properties.get(HOSTS);
if (hostObj == null) {
hostnameKey = HOSTS_HOST_NAME;
hostObj = properties.get(HOSTS_HOST_NAME);
}
if (hostObj != null) {
if (hostObj instanceof HashSet<?>) {
try {
Set<Map<String, String>> hostsSet = (Set<Map<String, String>>) hostObj;
for (Map<String, String> hostMap : hostsSet) {
if (hostMap.containsKey(hostnameKey)) {
String hostname = hostMap.get(hostnameKey);
hosts.add(hostname);
}
}
} catch (Exception e) {
LOG.warn("Host json in unparseable format. " + hostObj, e);
}
} else {
if (hostObj instanceof String) {
hosts.add((String) hostObj);
}
}
}
Object configObj = properties.get(DESIRED_CONFIGS);
if (configObj != null && configObj instanceof HashSet<?>) {
try {
Set<Map<String, Object>> configSet = (Set<Map<String, Object>>) configObj;
for (Map<String, Object> configMap : configSet) {
String type = (String) configMap.get(ConfigurationResourceProvider.TYPE);
String tag = (String) configMap.get(ConfigurationResourceProvider.TAG);
Map<String, String> configProperties = new HashMap<>();
Map<String, Map<String, String>> configAttributes = new HashMap<>();
for (Map.Entry<String, Object> entry : configMap.entrySet()) {
String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey());
if (propertyCategory != null && entry.getValue() != null) {
if ("properties".equals(propertyCategory)) {
configProperties.put(PropertyHelper.getPropertyName(entry.getKey()),
entry.getValue().toString());
} else if ("properties_attributes".equals(PropertyHelper.getPropertyCategory(propertyCategory))) {
String attributeName = PropertyHelper.getPropertyName(propertyCategory);
if (!configAttributes.containsKey(attributeName)) {
configAttributes.put(attributeName, new HashMap<>());
}
Map<String, String> attributeValues
= configAttributes.get(attributeName);
attributeValues.put(PropertyHelper.getPropertyName(entry.getKey()),
entry.getValue().toString());
}
}
}
Config config = configFactory.createReadOnly(type, tag, configProperties, configAttributes);
configurations.put(config.getType(), config);
}
} catch (Exception e) {
LOG.warn("Config json in unparseable format. " + configObj, e);
}
}
request.setConfigs(configurations);
request.setHosts(hosts);
return request;
} |
223551095_1399 | @Override
public Set<Resource> getResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<StackConfigurationDependencyRequest> requests =
new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<StackConfigurationDependencyResponse> responses = getResources(new Command<Set<StackConfigurationDependencyResponse>>() {
@Override
public Set<StackConfigurationDependencyResponse> invoke() throws AmbariException {
return getManagementController().getStackConfigurationDependencies(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (StackConfigurationDependencyResponse response : responses) {
Resource resource = new ResourceImpl(Type.StackConfigurationDependency);
setResourceProperty(resource, STACK_NAME_PROPERTY_ID,
response.getStackName(), requestedIds);
setResourceProperty(resource, STACK_VERSION_PROPERTY_ID,
response.getStackVersion(), requestedIds);
setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID,
response.getServiceName(), requestedIds);
setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID,
response.getPropertyName(), requestedIds);
setResourceProperty(resource, DEPENDENCY_NAME_PROPERTY_ID,
response.getDependencyName(), requestedIds);
setResourceProperty(resource, DEPENDENCY_TYPE_PROPERTY_ID,
response.getDependencyType(), requestedIds);
resources.add(resource);
}
return resources;
} |
223551095_1400 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> resources = new HashSet<>();
Set<Map<String, Object>> requestProps = getPropertyMaps(predicate);
for (Map<String, Object> properties : requestProps) {
try {
resources.addAll(getDependencyResources(properties,
getRequestPropertyIds(request, predicate)));
} catch (NoSuchResourceException | NoSuchParentResourceException e) {
if (requestProps.size() == 1) {
throw e;
}
}
}
return resources;
} |
223551095_1401 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> resources = new HashSet<>();
Set<Map<String, Object>> requestProps = getPropertyMaps(predicate);
for (Map<String, Object> properties : requestProps) {
try {
resources.addAll(getDependencyResources(properties,
getRequestPropertyIds(request, predicate)));
} catch (NoSuchResourceException | NoSuchParentResourceException e) {
if (requestProps.size() == 1) {
throw e;
}
}
}
return resources;
} |
223551095_1402 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<StackLevelConfigurationRequest> requests = new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() {
@Override
public Set<StackConfigurationResponse> invoke() throws AmbariException {
return getManagementController().getStackLevelConfigurations(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (StackConfigurationResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration);
setResourceProperty(resource, STACK_NAME_PROPERTY_ID,
response.getStackName(), requestedIds);
setResourceProperty(resource, STACK_VERSION_PROPERTY_ID,
response.getStackVersion(), requestedIds);
setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID,
response.getPropertyName(), requestedIds);
setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID,
response.getPropertyValue(), requestedIds);
setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID,
response.getPropertyValueAttributes(), requestedIds);
setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID,
response.getDependsOnProperties(), requestedIds);
setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID,
response.getPropertyDescription(), requestedIds);
//should not be returned if empty
if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) {
setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID,
response.getPropertyDisplayName(), requestedIds);
}
setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID,
response.getPropertyType(), requestedIds);
setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID,
response.getType(), requestedIds);
setDefaultPropertiesAttributes(resource, requestedIds);
for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) {
setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()),
attribute.getValue(), requestedIds);
}
resources.add(resource);
}
return resources;
} |
223551095_1403 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<StackLevelConfigurationRequest> requests = new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<StackConfigurationResponse> responses = getResources(new Command<Set<StackConfigurationResponse>>() {
@Override
public Set<StackConfigurationResponse> invoke() throws AmbariException {
return getManagementController().getStackLevelConfigurations(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (StackConfigurationResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.StackLevelConfiguration);
setResourceProperty(resource, STACK_NAME_PROPERTY_ID,
response.getStackName(), requestedIds);
setResourceProperty(resource, STACK_VERSION_PROPERTY_ID,
response.getStackVersion(), requestedIds);
setResourceProperty(resource, PROPERTY_NAME_PROPERTY_ID,
response.getPropertyName(), requestedIds);
setResourceProperty(resource, PROPERTY_VALUE_PROPERTY_ID,
response.getPropertyValue(), requestedIds);
setResourceProperty(resource, PROPERTY_VALUE_ATTRIBUTES_PROPERTY_ID,
response.getPropertyValueAttributes(), requestedIds);
setResourceProperty(resource, DEPENDS_ON_PROPERTY_ID,
response.getDependsOnProperties(), requestedIds);
setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID,
response.getPropertyDescription(), requestedIds);
//should not be returned if empty
if (StringUtils.isNotEmpty(response.getPropertyDisplayName())) {
setResourceProperty(resource, PROPERTY_DISPLAY_NAME_PROPERTY_ID,
response.getPropertyDisplayName(), requestedIds);
}
setResourceProperty(resource, PROPERTY_PROPERTY_TYPE_PROPERTY_ID,
response.getPropertyType(), requestedIds);
setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID,
response.getType(), requestedIds);
setDefaultPropertiesAttributes(resource, requestedIds);
for (Map.Entry<String, String> attribute : response.getPropertyAttributes().entrySet()) {
setResourceProperty(resource, PropertyHelper.getPropertyId("StackLevelConfigurations", attribute.getKey()),
attribute.getValue(), requestedIds);
}
resources.add(resource);
}
return resources;
} |
223551095_1404 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<StackServiceRequest> requests = new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() {
@Override
public Set<StackServiceResponse> invoke() throws AmbariException {
return getManagementController().getStackServices(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (StackServiceResponse response : responses) {
Resource resource = createResource(response, requestedIds);
resources.add(resource);
}
return resources;
} |
223551095_1405 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<StackServiceRequest> requests = new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<StackServiceResponse> responses = getResources(new Command<Set<StackServiceResponse>>() {
@Override
public Set<StackServiceResponse> invoke() throws AmbariException {
return getManagementController().getStackServices(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (StackServiceResponse response : responses) {
Resource resource = createResource(response, requestedIds);
resources.add(resource);
}
return resources;
} |
223551095_1406 | @Override
public QueryResponse queryForResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException {
return new QueryResponseImpl(getResources(request, predicate),
request.getSortRequest() != null, request.getPageRequest() != null,
alertsDAO.getCount(predicate));
} |
223551095_1407 | @Override
public Optional<String> getExternalHostName(String clusterName, String componentName) {
return getOverriddenHost(componentName).map(host -> replaceVariables(clusterName, host));
} |
223551095_1408 | @Override
public Optional<String> getExternalHostName(String clusterName, String componentName) {
return getOverriddenHost(componentName).map(host -> replaceVariables(clusterName, host));
} |
223551095_1409 | protected Resource toResource(ViewURLEntity viewURLEntity) {
Resource resource = new ResourceImpl(Resource.Type.ViewURL);
resource.setProperty(URL_NAME,viewURLEntity.getUrlName());
resource.setProperty(URL_SUFFIX,viewURLEntity.getUrlSuffix());
ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity();
if(viewInstanceEntity == null)
return resource;
ViewEntity viewEntity = viewInstanceEntity.getViewEntity();
String viewName = viewEntity.getCommonName();
String version = viewEntity.getVersion();
String name = viewInstanceEntity.getName();
resource.setProperty(VIEW_INSTANCE_NAME,name);
resource.setProperty(VIEW_INSTANCE_VERSION,version);
resource.setProperty(VIEW_INSTANCE_COMMON_NAME,viewName);
return resource;
} |
223551095_1410 | @Override
public RequestStatus createResources(Request request)
throws SystemException,
UnsupportedPropertyException,
ResourceAlreadyExistsException,
NoSuchParentResourceException {
throw new SystemException("The request is not supported");
} |
223551095_1411 | @Override
public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
throw new SystemException("The request is not supported");
} |
223551095_1412 | @Override
public RequestStatus deleteResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
throw new SystemException("The request is not supported");
} |
223551095_1413 | @Override
public RequestStatus createResources(Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException,
NoSuchParentResourceException {
throw new UnsupportedOperationException();
} |
223551095_1414 | @Override
public RequestStatus updateResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Iterator<Map<String,Object>> iterator = request.getProperties().iterator();
if (iterator.hasNext()) {
Map<String,Object> updateProperties = iterator.next();
List<StageEntity> entities = dao.findAll(request, predicate);
for (StageEntity entity : entities) {
String stageStatus = (String) updateProperties.get(STAGE_STATUS);
if (stageStatus != null) {
HostRoleStatus desiredStatus = HostRoleStatus.valueOf(stageStatus);
dao.updateStageStatus(entity, desiredStatus,
getManagementController().getActionManager());
}
}
}
notifyUpdate(Resource.Type.Stage, request, predicate);
return getRequestStatus(null);
} |
223551095_1415 | @Override
public RequestStatus deleteResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
throw new UnsupportedOperationException();
} |
223551095_1416 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = new LinkedHashSet<>();
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
// !!! poor mans cache. toResource() shouldn't be calling the db
// every time, when the request id is likely the same for each stageEntity
Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<>();
List<StageEntity> entities = dao.findAll(request, predicate);
for (StageEntity entity : entities) {
results.add(StageResourceProvider.toResource(cache, entity, propertyIds));
}
cache.clear();
// !!! check the id passed to see if it's a LogicalRequest. This safeguards against
// iterating all stages for all requests. That is a problem when the request
// is for an Upgrade, but was pulling the data anyway.
Map<String, Object> map = PredicateHelper.getProperties(predicate);
if (map.containsKey(STAGE_REQUEST_ID)) {
Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString());
LogicalRequest lr = topologyManager.getRequest(requestId);
if (null != lr) {
Collection<StageEntity> topologyManagerStages = lr.getStageEntities();
// preload summaries as it contains summaries for all stages within this request
Map<Long, HostRoleCommandStatusSummaryDTO> summary = topologyManager.getStageSummaries(requestId);
cache.put(requestId, summary);
for (StageEntity entity : topologyManagerStages) {
Resource stageResource = toResource(cache, entity, propertyIds);
if (predicate.evaluate(stageResource)) {
results.add(stageResource);
}
}
}
} else {
Collection<StageEntity> topologyManagerStages = topologyManager.getStages();
for (StageEntity entity : topologyManagerStages) {
if (!cache.containsKey(entity.getRequestId())) {
Map<Long, HostRoleCommandStatusSummaryDTO> summary = topologyManager.getStageSummaries(entity.getRequestId());
cache.put(entity.getRequestId(), summary);
}
Resource stageResource = toResource(cache, entity, propertyIds);
if (predicate.evaluate(stageResource)) {
results.add(stageResource);
}
}
}
return results;
} |
223551095_1417 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = new LinkedHashSet<>();
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
// !!! poor mans cache. toResource() shouldn't be calling the db
// every time, when the request id is likely the same for each stageEntity
Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<>();
List<StageEntity> entities = dao.findAll(request, predicate);
for (StageEntity entity : entities) {
results.add(StageResourceProvider.toResource(cache, entity, propertyIds));
}
cache.clear();
// !!! check the id passed to see if it's a LogicalRequest. This safeguards against
// iterating all stages for all requests. That is a problem when the request
// is for an Upgrade, but was pulling the data anyway.
Map<String, Object> map = PredicateHelper.getProperties(predicate);
if (map.containsKey(STAGE_REQUEST_ID)) {
Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString());
LogicalRequest lr = topologyManager.getRequest(requestId);
if (null != lr) {
Collection<StageEntity> topologyManagerStages = lr.getStageEntities();
// preload summaries as it contains summaries for all stages within this request
Map<Long, HostRoleCommandStatusSummaryDTO> summary = topologyManager.getStageSummaries(requestId);
cache.put(requestId, summary);
for (StageEntity entity : topologyManagerStages) {
Resource stageResource = toResource(cache, entity, propertyIds);
if (predicate.evaluate(stageResource)) {
results.add(stageResource);
}
}
}
} else {
Collection<StageEntity> topologyManagerStages = topologyManager.getStages();
for (StageEntity entity : topologyManagerStages) {
if (!cache.containsKey(entity.getRequestId())) {
Map<Long, HostRoleCommandStatusSummaryDTO> summary = topologyManager.getStageSummaries(entity.getRequestId());
cache.put(entity.getRequestId(), summary);
}
Resource stageResource = toResource(cache, entity, propertyIds);
if (predicate.evaluate(stageResource)) {
results.add(stageResource);
}
}
}
return results;
} |
223551095_1418 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = new LinkedHashSet<>();
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
// !!! poor mans cache. toResource() shouldn't be calling the db
// every time, when the request id is likely the same for each stageEntity
Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<>();
List<StageEntity> entities = dao.findAll(request, predicate);
for (StageEntity entity : entities) {
results.add(StageResourceProvider.toResource(cache, entity, propertyIds));
}
cache.clear();
// !!! check the id passed to see if it's a LogicalRequest. This safeguards against
// iterating all stages for all requests. That is a problem when the request
// is for an Upgrade, but was pulling the data anyway.
Map<String, Object> map = PredicateHelper.getProperties(predicate);
if (map.containsKey(STAGE_REQUEST_ID)) {
Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString());
LogicalRequest lr = topologyManager.getRequest(requestId);
if (null != lr) {
Collection<StageEntity> topologyManagerStages = lr.getStageEntities();
// preload summaries as it contains summaries for all stages within this request
Map<Long, HostRoleCommandStatusSummaryDTO> summary = topologyManager.getStageSummaries(requestId);
cache.put(requestId, summary);
for (StageEntity entity : topologyManagerStages) {
Resource stageResource = toResource(cache, entity, propertyIds);
if (predicate.evaluate(stageResource)) {
results.add(stageResource);
}
}
}
} else {
Collection<StageEntity> topologyManagerStages = topologyManager.getStages();
for (StageEntity entity : topologyManagerStages) {
if (!cache.containsKey(entity.getRequestId())) {
Map<Long, HostRoleCommandStatusSummaryDTO> summary = topologyManager.getStageSummaries(entity.getRequestId());
cache.put(entity.getRequestId(), summary);
}
Resource stageResource = toResource(cache, entity, propertyIds);
if (predicate.evaluate(stageResource)) {
results.add(stageResource);
}
}
}
return results;
} |
223551095_1419 | @Override
public QueryResponse queryForResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = getResources(request, predicate);
return new QueryResponseImpl(results, request.getSortRequest() != null, false, results.size());
} |
223551095_1420 | @Override
public RequestStatus updateResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Iterator<Map<String,Object>> iterator = request.getProperties().iterator();
if (iterator.hasNext()) {
Map<String,Object> updateProperties = iterator.next();
List<StageEntity> entities = dao.findAll(request, predicate);
for (StageEntity entity : entities) {
String stageStatus = (String) updateProperties.get(STAGE_STATUS);
if (stageStatus != null) {
HostRoleStatus desiredStatus = HostRoleStatus.valueOf(stageStatus);
dao.updateStageStatus(entity, desiredStatus,
getManagementController().getActionManager());
}
}
}
notifyUpdate(Resource.Type.Stage, request, predicate);
return getRequestStatus(null);
} |
223551095_1421 | @Override
public RequestStatus createResources(Request request)
throws SystemException, UnsupportedPropertyException,
ResourceAlreadyExistsException, NoSuchParentResourceException {
IvoryService service = getService();
Set<Map<String, Object>> propertiesSet = request.getProperties();
for(Map<String, Object> propertyMap : propertiesSet) {
service.submitFeed(getFeed((String) propertyMap.get(FEED_NAME_PROPERTY_ID), propertyMap));
}
return new RequestStatusImpl(null);
} |
223551095_1422 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
IvoryService service = getService();
List<String> feedNames = service.getFeedNames();
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<Resource> resources = new HashSet<>();
for (String feedName : feedNames ) {
Feed feed = service.getFeed(feedName);
Resource resource = new ResourceImpl(Resource.Type.DRFeed);
setResourceProperty(resource, FEED_NAME_PROPERTY_ID,
feed.getName(), requestedIds);
setResourceProperty(resource, FEED_DESCRIPTION_PROPERTY_ID,
feed.getDescription(), requestedIds);
setResourceProperty(resource, FEED_STATUS_PROPERTY_ID,
feed.getStatus(), requestedIds);
setResourceProperty(resource, FEED_SCHEDULE_PROPERTY_ID,
feed.getSchedule(), requestedIds);
setResourceProperty(resource, FEED_SOURCE_CLUSTER_NAME_PROPERTY_ID,
feed.getSourceClusterName(), requestedIds);
setResourceProperty(resource, FEED_SOURCE_CLUSTER_START_PROPERTY_ID,
feed.getSourceClusterStart(), requestedIds);
setResourceProperty(resource, FEED_SOURCE_CLUSTER_END_PROPERTY_ID,
feed.getSourceClusterEnd(), requestedIds);
setResourceProperty(resource, FEED_SOURCE_CLUSTER_LIMIT_PROPERTY_ID,
feed.getSourceClusterLimit(), requestedIds);
setResourceProperty(resource, FEED_SOURCE_CLUSTER_ACTION_PROPERTY_ID,
feed.getSourceClusterAction(), requestedIds);
setResourceProperty(resource, FEED_TARGET_CLUSTER_NAME_PROPERTY_ID,
feed.getTargetClusterName(), requestedIds);
setResourceProperty(resource, FEED_TARGET_CLUSTER_START_PROPERTY_ID,
feed.getTargetClusterStart(), requestedIds);
setResourceProperty(resource, FEED_TARGET_CLUSTER_END_PROPERTY_ID,
feed.getTargetClusterEnd(), requestedIds);
setResourceProperty(resource, FEED_TARGET_CLUSTER_LIMIT_PROPERTY_ID,
feed.getTargetClusterLimit(), requestedIds);
setResourceProperty(resource, FEED_TARGET_CLUSTER_ACTION_PROPERTY_ID,
feed.getTargetClusterAction(), requestedIds);
setResourceProperty(resource, FEED_PROPERTIES_PROPERTY_ID,
feed.getProperties(), requestedIds);
if (predicate == null || predicate.evaluate(resource)) {
resources.add(resource);
}
}
return resources;
} |
223551095_1423 | @Override
public RequestStatus updateResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
Iterator<Map<String,Object>> iterator = request.getProperties().iterator();
if (iterator.hasNext()) {
Map<String, Object> propertyMap = iterator.next();
String desiredStatus = (String) propertyMap.get(FEED_STATUS_PROPERTY_ID);
// get all the feeds that pass the predicate check
Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate);
// update all the matching feeds with the property values from the request
for (Resource resource : resources) {
IvoryService service = getService();
if (desiredStatus != null) {
String status = (String) resource.getPropertyValue(FEED_STATUS_PROPERTY_ID);
String feedName = (String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID);
if (desiredStatus.equals("SCHEDULED")) {
service.scheduleFeed(feedName);
} else if (desiredStatus.equals("SUSPENDED")) {
service.suspendFeed(feedName);
} else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) {
service.resumeFeed(feedName);
}
}
service.updateFeed(getFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID),
getUpdateMap(resource, propertyMap)));
}
}
return new RequestStatusImpl(null);
} |
223551095_1424 | @Override
public RequestStatus deleteResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
IvoryService service = getService();
// get all the feeds that pass the predicate check
Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate);
for (Resource resource : resources) {
// delete all the matching feeds with the property values from the request
service.deleteFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID));
}
return new RequestStatusImpl(null);
} |
223551095_1425 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
StackAdvisorRequest recommendationRequest = prepareStackAdvisorRequest(request);
final RecommendationResponse response;
try {
response = saHelper.recommend(recommendationRequest);
} catch (StackAdvisorRequestException e) {
LOG.warn("Error occured during recommendation", e);
throw new IllegalArgumentException(e.getMessage(), e);
} catch (StackAdvisorException e) {
LOG.warn("Error occured during recommendation", e);
throw new SystemException(e.getMessage(), e);
}
Resource recommendation = createResources(new Command<Resource>() {
@Override
public Resource invoke() throws AmbariException {
Resource resource = new ResourceImpl(Resource.Type.Recommendation);
setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds());
setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(),
getPropertyIds());
setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion()
.getStackVersion(), getPropertyIds());
setResourceProperty(resource, HOSTS_PROPERTY_ID, response.getHosts(), getPropertyIds());
setResourceProperty(resource, SERVICES_PROPERTY_ID, response.getServices(),
getPropertyIds());
setResourceProperty(resource, CONFIG_GROUPS_PROPERTY_ID,
response.getRecommendations().getConfigGroups(), getPropertyIds());
setResourceProperty(resource, BLUEPRINT_CONFIGURATIONS_PROPERTY_ID, response
.getRecommendations().getBlueprint().getConfigurations(), getPropertyIds());
Set<HostGroup> hostGroups = response.getRecommendations().getBlueprint().getHostGroups();
List<Map<String, Object>> listGroupProps = new ArrayList<>();
for (HostGroup hostGroup : hostGroups) {
Map<String, Object> mapGroupProps = new HashMap<>();
mapGroupProps.put(BLUEPRINT_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName());
mapGroupProps
.put(BLUEPRINT_HOST_GROUPS_COMPONENTS_PROPERTY_ID, hostGroup.getComponents());
listGroupProps.add(mapGroupProps);
}
setResourceProperty(resource, BLUEPRINT_HOST_GROUPS_PROPERTY_ID, listGroupProps,
getPropertyIds());
Set<BindingHostGroup> bindingHostGroups = response.getRecommendations()
.getBlueprintClusterBinding().getHostGroups();
List<Map<String, Object>> listBindingGroupProps = new ArrayList<>();
for (BindingHostGroup hostGroup : bindingHostGroups) {
Map<String, Object> mapGroupProps = new HashMap<>();
mapGroupProps.put(BINDING_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName());
mapGroupProps.put(BINDING_HOST_GROUPS_HOSTS_PROPERTY_ID, hostGroup.getHosts());
listBindingGroupProps.add(mapGroupProps);
}
setResourceProperty(resource, BINDING_HOST_GROUPS_PROPERTY_ID, listBindingGroupProps,
getPropertyIds());
return resource;
}
});
notifyCreate(Resource.Type.Recommendation, request);
Set<Resource> resources = new HashSet<>(Arrays.asList(recommendation));
return new RequestStatusImpl(null, resources);
} |
223551095_1426 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1427 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1428 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1429 | @Override
public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException,
UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
Set<Resource> results = new HashSet<>();
Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME);
if (null == clusterName || clusterName.isEmpty()) {
throw new IllegalArgumentException(
"The cluster name is required when querying for upgrades");
}
Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
List<UpgradeEntity> upgrades = new ArrayList<>();
String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID);
if (null != upgradeIdStr) {
UpgradeEntity upgrade = s_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr));
if (null != upgrade) {
upgrades.add(upgrade);
}
} else {
upgrades = s_upgradeDAO.findUpgrades(cluster.getClusterId());
}
for (UpgradeEntity entity : upgrades) {
Resource r = toResource(entity, clusterName, requestPropertyIds);
results.add(r);
RequestEntity rentity = s_requestDAO.findByPK(entity.getRequestId());
setResourceProperty(r, REQUEST_CONTEXT_ID, rentity.getRequestContext(), requestPropertyIds);
setResourceProperty(r, REQUEST_TYPE_ID, rentity.getRequestType(), requestPropertyIds);
setResourceProperty(r, REQUEST_CREATE_TIME_ID, rentity.getCreateTime(), requestPropertyIds);
setResourceProperty(r, REQUEST_START_TIME_ID, rentity.getStartTime(), requestPropertyIds);
setResourceProperty(r, REQUEST_END_TIME_ID, rentity.getEndTime(), requestPropertyIds);
setResourceProperty(r, REQUEST_EXCLUSIVE_ID, rentity.isExclusive(), requestPropertyIds);
Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts(
entity.getRequestId());
CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet());
if (calc.getStatus() == HostRoleStatus.ABORTED && entity.isSuspended()) {
double percent = calculateAbortedProgress(summary);
setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, percent*100, requestPropertyIds);
} else {
setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds);
}
setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds);
}
}
return results;
} |
223551095_1430 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1431 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1432 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1433 | @Override
public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only update one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> propertyMap = requestMaps.iterator().next();
final String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
String requestIdProperty = (String) propertyMap.get(UPGRADE_REQUEST_ID);
if (null == requestIdProperty) {
throw new IllegalArgumentException(String.format("%s is required", UPGRADE_REQUEST_ID));
}
long requestId = Long.parseLong(requestIdProperty);
UpgradeEntity upgradeEntity = s_upgradeDAO.findUpgradeByRequestId(requestId);
if( null == upgradeEntity){
String exceptionMessage = MessageFormat.format("The upgrade with request ID {0} was not found", requestIdProperty);
throw new NoSuchParentResourceException(exceptionMessage);
}
// the properties which are allowed to be updated; the request must include
// at least 1
List<String> updatableProperties = Lists.newArrayList(UPGRADE_REQUEST_STATUS,
UPGRADE_SKIP_FAILURES, UPGRADE_SKIP_SC_FAILURES);
boolean isRequiredPropertyInRequest = CollectionUtils.containsAny(updatableProperties,
propertyMap.keySet());
if (!isRequiredPropertyInRequest) {
String exceptionMessage = MessageFormat.format(
"At least one of the following properties is required in the request: {0}",
StringUtils.join(updatableProperties, ", "));
throw new IllegalArgumentException(exceptionMessage);
}
String requestStatus = (String) propertyMap.get(UPGRADE_REQUEST_STATUS);
String skipFailuresRequestProperty = (String) propertyMap.get(UPGRADE_SKIP_FAILURES);
String skipServiceCheckFailuresRequestProperty = (String) propertyMap.get(UPGRADE_SKIP_SC_FAILURES);
if (null != requestStatus) {
HostRoleStatus status = HostRoleStatus.valueOf(requestStatus);
// When aborting an upgrade, the suspend flag must be present to indicate
// if the upgrade is merely being paused (suspended=true) or aborted to initiate a downgrade (suspended=false).
boolean suspended = false;
if (status == HostRoleStatus.ABORTED && !propertyMap.containsKey(UPGRADE_SUSPENDED)){
throw new IllegalArgumentException(String.format(
"When changing the state of an upgrade to %s, the %s property is required to be either true or false.",
status, UPGRADE_SUSPENDED ));
} else if (status == HostRoleStatus.ABORTED) {
suspended = Boolean.valueOf((String) propertyMap.get(UPGRADE_SUSPENDED));
}
try {
setUpgradeRequestStatus(cluster, requestId, status, suspended, propertyMap);
} catch (AmbariException ambariException) {
throw new SystemException(ambariException.getMessage(), ambariException);
}
}
// if either of the skip failure settings are in the request, then we need
// to iterate over the entire series of tasks anyway, so do them both at the
// same time
if (StringUtils.isNotEmpty(skipFailuresRequestProperty)
|| StringUtils.isNotEmpty(skipServiceCheckFailuresRequestProperty)) {
// grab the current settings for both
boolean skipFailures = upgradeEntity.isComponentFailureAutoSkipped();
boolean skipServiceCheckFailures = upgradeEntity.isServiceCheckFailureAutoSkipped();
if (null != skipFailuresRequestProperty) {
skipFailures = Boolean.parseBoolean(skipFailuresRequestProperty);
}
if (null != skipServiceCheckFailuresRequestProperty) {
skipServiceCheckFailures = Boolean.parseBoolean(skipServiceCheckFailuresRequestProperty);
}
s_hostRoleCommandDAO.updateAutomaticSkipOnFailure(requestId, skipFailures, skipServiceCheckFailures);
upgradeEntity.setAutoSkipComponentFailures(skipFailures);
upgradeEntity.setAutoSkipServiceCheckFailures(skipServiceCheckFailures);
s_upgradeDAO.merge(upgradeEntity);
}
return getRequestStatus(null);
} |
223551095_1434 | @Override
public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only update one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> propertyMap = requestMaps.iterator().next();
final String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
String requestIdProperty = (String) propertyMap.get(UPGRADE_REQUEST_ID);
if (null == requestIdProperty) {
throw new IllegalArgumentException(String.format("%s is required", UPGRADE_REQUEST_ID));
}
long requestId = Long.parseLong(requestIdProperty);
UpgradeEntity upgradeEntity = s_upgradeDAO.findUpgradeByRequestId(requestId);
if( null == upgradeEntity){
String exceptionMessage = MessageFormat.format("The upgrade with request ID {0} was not found", requestIdProperty);
throw new NoSuchParentResourceException(exceptionMessage);
}
// the properties which are allowed to be updated; the request must include
// at least 1
List<String> updatableProperties = Lists.newArrayList(UPGRADE_REQUEST_STATUS,
UPGRADE_SKIP_FAILURES, UPGRADE_SKIP_SC_FAILURES);
boolean isRequiredPropertyInRequest = CollectionUtils.containsAny(updatableProperties,
propertyMap.keySet());
if (!isRequiredPropertyInRequest) {
String exceptionMessage = MessageFormat.format(
"At least one of the following properties is required in the request: {0}",
StringUtils.join(updatableProperties, ", "));
throw new IllegalArgumentException(exceptionMessage);
}
String requestStatus = (String) propertyMap.get(UPGRADE_REQUEST_STATUS);
String skipFailuresRequestProperty = (String) propertyMap.get(UPGRADE_SKIP_FAILURES);
String skipServiceCheckFailuresRequestProperty = (String) propertyMap.get(UPGRADE_SKIP_SC_FAILURES);
if (null != requestStatus) {
HostRoleStatus status = HostRoleStatus.valueOf(requestStatus);
// When aborting an upgrade, the suspend flag must be present to indicate
// if the upgrade is merely being paused (suspended=true) or aborted to initiate a downgrade (suspended=false).
boolean suspended = false;
if (status == HostRoleStatus.ABORTED && !propertyMap.containsKey(UPGRADE_SUSPENDED)){
throw new IllegalArgumentException(String.format(
"When changing the state of an upgrade to %s, the %s property is required to be either true or false.",
status, UPGRADE_SUSPENDED ));
} else if (status == HostRoleStatus.ABORTED) {
suspended = Boolean.valueOf((String) propertyMap.get(UPGRADE_SUSPENDED));
}
try {
setUpgradeRequestStatus(cluster, requestId, status, suspended, propertyMap);
} catch (AmbariException ambariException) {
throw new SystemException(ambariException.getMessage(), ambariException);
}
}
// if either of the skip failure settings are in the request, then we need
// to iterate over the entire series of tasks anyway, so do them both at the
// same time
if (StringUtils.isNotEmpty(skipFailuresRequestProperty)
|| StringUtils.isNotEmpty(skipServiceCheckFailuresRequestProperty)) {
// grab the current settings for both
boolean skipFailures = upgradeEntity.isComponentFailureAutoSkipped();
boolean skipServiceCheckFailures = upgradeEntity.isServiceCheckFailureAutoSkipped();
if (null != skipFailuresRequestProperty) {
skipFailures = Boolean.parseBoolean(skipFailuresRequestProperty);
}
if (null != skipServiceCheckFailuresRequestProperty) {
skipServiceCheckFailures = Boolean.parseBoolean(skipServiceCheckFailuresRequestProperty);
}
s_hostRoleCommandDAO.updateAutomaticSkipOnFailure(requestId, skipFailures, skipServiceCheckFailures);
upgradeEntity.setAutoSkipComponentFailures(skipFailures);
upgradeEntity.setAutoSkipServiceCheckFailures(skipServiceCheckFailures);
s_upgradeDAO.merge(upgradeEntity);
}
return getRequestStatus(null);
} |
223551095_1435 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1436 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1437 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1438 | @Override
public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only update one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> propertyMap = requestMaps.iterator().next();
final String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
String requestIdProperty = (String) propertyMap.get(UPGRADE_REQUEST_ID);
if (null == requestIdProperty) {
throw new IllegalArgumentException(String.format("%s is required", UPGRADE_REQUEST_ID));
}
long requestId = Long.parseLong(requestIdProperty);
UpgradeEntity upgradeEntity = s_upgradeDAO.findUpgradeByRequestId(requestId);
if( null == upgradeEntity){
String exceptionMessage = MessageFormat.format("The upgrade with request ID {0} was not found", requestIdProperty);
throw new NoSuchParentResourceException(exceptionMessage);
}
// the properties which are allowed to be updated; the request must include
// at least 1
List<String> updatableProperties = Lists.newArrayList(UPGRADE_REQUEST_STATUS,
UPGRADE_SKIP_FAILURES, UPGRADE_SKIP_SC_FAILURES);
boolean isRequiredPropertyInRequest = CollectionUtils.containsAny(updatableProperties,
propertyMap.keySet());
if (!isRequiredPropertyInRequest) {
String exceptionMessage = MessageFormat.format(
"At least one of the following properties is required in the request: {0}",
StringUtils.join(updatableProperties, ", "));
throw new IllegalArgumentException(exceptionMessage);
}
String requestStatus = (String) propertyMap.get(UPGRADE_REQUEST_STATUS);
String skipFailuresRequestProperty = (String) propertyMap.get(UPGRADE_SKIP_FAILURES);
String skipServiceCheckFailuresRequestProperty = (String) propertyMap.get(UPGRADE_SKIP_SC_FAILURES);
if (null != requestStatus) {
HostRoleStatus status = HostRoleStatus.valueOf(requestStatus);
// When aborting an upgrade, the suspend flag must be present to indicate
// if the upgrade is merely being paused (suspended=true) or aborted to initiate a downgrade (suspended=false).
boolean suspended = false;
if (status == HostRoleStatus.ABORTED && !propertyMap.containsKey(UPGRADE_SUSPENDED)){
throw new IllegalArgumentException(String.format(
"When changing the state of an upgrade to %s, the %s property is required to be either true or false.",
status, UPGRADE_SUSPENDED ));
} else if (status == HostRoleStatus.ABORTED) {
suspended = Boolean.valueOf((String) propertyMap.get(UPGRADE_SUSPENDED));
}
try {
setUpgradeRequestStatus(cluster, requestId, status, suspended, propertyMap);
} catch (AmbariException ambariException) {
throw new SystemException(ambariException.getMessage(), ambariException);
}
}
// if either of the skip failure settings are in the request, then we need
// to iterate over the entire series of tasks anyway, so do them both at the
// same time
if (StringUtils.isNotEmpty(skipFailuresRequestProperty)
|| StringUtils.isNotEmpty(skipServiceCheckFailuresRequestProperty)) {
// grab the current settings for both
boolean skipFailures = upgradeEntity.isComponentFailureAutoSkipped();
boolean skipServiceCheckFailures = upgradeEntity.isServiceCheckFailureAutoSkipped();
if (null != skipFailuresRequestProperty) {
skipFailures = Boolean.parseBoolean(skipFailuresRequestProperty);
}
if (null != skipServiceCheckFailuresRequestProperty) {
skipServiceCheckFailures = Boolean.parseBoolean(skipServiceCheckFailuresRequestProperty);
}
s_hostRoleCommandDAO.updateAutomaticSkipOnFailure(requestId, skipFailures, skipServiceCheckFailures);
upgradeEntity.setAutoSkipComponentFailures(skipFailures);
upgradeEntity.setAutoSkipServiceCheckFailures(skipServiceCheckFailures);
s_upgradeDAO.merge(upgradeEntity);
}
return getRequestStatus(null);
} |
223551095_1439 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1440 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1441 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1442 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1443 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1444 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1445 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1446 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1447 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1448 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1449 | @Override
public RequestStatus createResources(final Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
Set<Map<String, Object>> requestMaps = request.getProperties();
if (requestMaps.size() > 1) {
throw new SystemException("Can only initiate one upgrade per request.");
}
// !!! above check ensures only one
final Map<String, Object> requestMap = requestMaps.iterator().next();
final String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
final Cluster cluster;
try {
cluster = clusters.get().getCluster(clusterName);
} catch (AmbariException e) {
throw new NoSuchParentResourceException(
String.format("Cluster %s could not be loaded", clusterName));
}
if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, cluster.getResourceId(),
EnumSet.of(RoleAuthorization.CLUSTER_UPGRADE_DOWNGRADE_STACK))) {
throw new AuthorizationException("The authenticated user does not have authorization to " +
"manage upgrade and downgrade");
}
UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
@Override
public UpgradeEntity invoke() throws AmbariException, AuthorizationException {
// create the context, validating the properties in the process
final UpgradeContext upgradeContext = s_upgradeContextFactory.create(cluster, requestMap);
try {
return createUpgrade(upgradeContext);
} catch (Exception e) {
LOG.error("Error appears during upgrade task submitting", e);
// Any error caused in the createUpgrade will initiate transaction
// rollback
// As we operate inside with cluster data, any cache which belongs to
// cluster need to be flushed
clusters.get().invalidate(cluster);
throw e;
}
}
});
if (null == entity) {
throw new SystemException("Could not load upgrade");
}
notifyCreate(Resource.Type.Upgrade, request);
Resource res = new ResourceImpl(Resource.Type.Upgrade);
res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
return new RequestStatusImpl(null, Collections.singleton(res));
} |
223551095_1454 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<RepositoryRequest> requests = new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<RepositoryResponse> responses = getResources(new Command<Set<RepositoryResponse>>() {
@Override
public Set<RepositoryResponse> invoke() throws AmbariException {
return getManagementController().getRepositories(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (RepositoryResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.Repository);
setResourceProperty(resource, REPOSITORY_STACK_NAME_PROPERTY_ID, response.getStackName(), requestedIds);
setResourceProperty(resource, REPOSITORY_STACK_VERSION_PROPERTY_ID, response.getStackVersion(), requestedIds);
setResourceProperty(resource, REPOSITORY_REPO_NAME_PROPERTY_ID, response.getRepoName(), requestedIds);
setResourceProperty(resource, REPOSITORY_DISTRIBUTION_PROPERTY_ID, response.getDistribution(), requestedIds);
setResourceProperty(resource, REPOSITORY_COMPONENTS_PROPERTY_ID, response.getComponents(), requestedIds);
setResourceProperty(resource, REPOSITORY_BASE_URL_PROPERTY_ID, response.getBaseUrl(), requestedIds);
setResourceProperty(resource, REPOSITORY_OS_TYPE_PROPERTY_ID, response.getOsType(), requestedIds);
setResourceProperty(resource, REPOSITORY_REPO_ID_PROPERTY_ID, response.getRepoId(), requestedIds);
setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID, response.getMirrorsList(), requestedIds);
setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID, response.getDefaultBaseUrl(), requestedIds);
setResourceProperty(resource, REPOSITORY_UNIQUE_PROPERTY_ID, response.isUnique(), requestedIds);
setResourceProperty(resource, REPOSITORY_TAGS_PROPERTY_ID, response.getTags(), requestedIds);
setResourceProperty(resource, REPOSITORY_APPLICABLE_SERVICES_PROPERTY_ID, response.getApplicableServices(), requestedIds);
if (null != response.getClusterVersionId()) {
setResourceProperty(resource, REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID, response.getClusterVersionId(), requestedIds);
}
if (null != response.getRepositoryVersionId()) {
setResourceProperty(resource, REPOSITORY_REPOSITORY_VERSION_ID_PROPERTY_ID, response.getRepositoryVersionId(), requestedIds);
}
if (null != response.getVersionDefinitionId()) {
setResourceProperty(resource, REPOSITORY_VERSION_DEFINITION_ID_PROPERTY_ID,
response.getVersionDefinitionId(), requestedIds);
}
resources.add(resource);
}
return resources;
} |
223551095_1455 | @Override
public RequestStatus updateResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<RepositoryRequest> requestsToVerifyBaseURLs = new HashSet<>();
Iterator<Map<String,Object>> iterator = request.getProperties().iterator();
if (iterator.hasNext()) {
for (Map<String, Object> propertyMap : getPropertyMaps(iterator.next(), predicate)) {
RepositoryRequest rr = getRequest(propertyMap);
if(rr.isVerifyBaseUrl()) {
requestsToVerifyBaseURLs.add(rr);
}
}
}
//Validation only - used by the cluster installation
try {
getManagementController().verifyRepositories(requestsToVerifyBaseURLs);
} catch (AmbariException e) {
throw new SystemException("", e);
}
return getRequestStatus(null);
} |
223551095_1456 | @Override
public RequestStatus createResources(Request request) throws SystemException,
UnsupportedPropertyException, ResourceAlreadyExistsException,
NoSuchParentResourceException {
final Set<RequestScheduleRequest> requests = new HashSet<>();
for (Map<String, Object> propertyMap : request.getProperties()) {
requests.add(getRequestScheduleRequest(propertyMap));
}
Set<RequestScheduleResponse> responses =
createResources(new Command<Set<RequestScheduleResponse>>() {
@Override
public Set<RequestScheduleResponse> invoke() throws AmbariException {
return createRequestSchedules(requests);
}
});
notifyCreate(Resource.Type.RequestSchedule, request);
Set<Resource> associatedResources = new HashSet<>();
for (RequestScheduleResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.RequestSchedule);
resource.setProperty(ID, response.getId());
associatedResources.add(resource);
}
return getRequestStatus(null, associatedResources);
} |
223551095_1457 | private synchronized void updateRequestSchedule
(Set<RequestScheduleRequest> requests) throws AmbariException {
if (requests.isEmpty()) {
LOG.warn("Received an empty requests set");
return;
}
Clusters clusters = getManagementController().getClusters();
for (RequestScheduleRequest request : requests) {
validateRequest(request);
Cluster cluster;
try {
cluster = clusters.getCluster(request.getClusterName());
} catch (ClusterNotFoundException e) {
throw new ParentObjectNotFoundException(
"Attempted to add a request schedule to a cluster which doesn't " +
"exist", e);
}
if (request.getId() == null) {
throw new AmbariException("Id is a required parameter.");
}
RequestExecution requestExecution =
cluster.getAllRequestExecutions().get(request.getId());
if (requestExecution == null) {
throw new AmbariException("Request Schedule not found "
+ ", clusterName = " + request.getClusterName()
+ ", description = " + request.getDescription()
+ ", id = " + request.getId());
}
String username = getManagementController().getAuthName();
Integer userId = getManagementController().getAuthId();
requestExecution.setBatch(request.getBatch());
requestExecution.setDescription(request.getDescription());
requestExecution.setSchedule(request.getSchedule());
if (request.getStatus() != null && isValidRequestScheduleStatus
(request.getStatus())) {
requestExecution.setStatus(RequestExecution.Status.valueOf(request.getStatus()));
}
requestExecution.setUpdateUser(username);
requestExecution.setAuthenticatedUserId(userId);
LOG.info("Persisting updated Request Schedule "
+ ", clusterName = " + request.getClusterName()
+ ", description = " + request.getDescription()
+ ", user = " + username);
requestExecution.persist();
// Update schedule for the batch
getManagementController().getExecutionScheduleManager()
.updateBatchSchedule(requestExecution);
}
} |
223551095_1458 | @Override
public Set<Resource> getResources(Request request, Predicate predicate) throws
SystemException, UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException {
final Set<RequestScheduleRequest> requests = new HashSet<>();
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequestScheduleRequest(propertyMap));
}
Set<RequestScheduleResponse> responses =
getResources(new Command<Set<RequestScheduleResponse>>() {
@Override
public Set<RequestScheduleResponse> invoke() throws AmbariException {
return getRequestSchedules(requests);
}
});
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<Resource> resources = new HashSet<>();
for (RequestScheduleResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.RequestSchedule);
setResourceProperty(resource, ID,
response.getId(), requestedIds);
setResourceProperty(resource, CLUSTER_NAME,
response.getClusterName(), requestedIds);
setResourceProperty(resource, DESCRIPTION,
response.getDescription(), requestedIds);
setResourceProperty(resource, STATUS,
response.getStatus(), requestedIds);
setResourceProperty(resource, LAST_EXECUTION_STATUS,
response.getLastExecutionStatus(), requestedIds);
setResourceProperty(resource, BATCH,
response.getBatch(), requestedIds);
setResourceProperty(resource, SCHEDULE,
response.getSchedule(), requestedIds);
setResourceProperty(resource, CREATE_USER,
response.getCreateUser(), requestedIds);
setResourceProperty(resource, AUTHENTICATED_USER,
response.getAuthenticatedUserId(), requestedIds);
setResourceProperty(resource, CREATE_TIME,
response.getCreateTime(), requestedIds);
setResourceProperty(resource, UPDATE_USER,
response.getUpdateUser(), requestedIds);
setResourceProperty(resource, UPDATE_TIME,
response.getUpdateTime(), requestedIds);
resources.add(resource);
}
return resources;
} |
223551095_1459 | private synchronized void deleteRequestSchedule(RequestScheduleRequest request)
throws AmbariException {
if (request.getId() == null) {
throw new AmbariException("Id is a required field.");
}
Clusters clusters = getManagementController().getClusters();
Cluster cluster;
try {
cluster = clusters.getCluster(request.getClusterName());
} catch (ClusterNotFoundException e) {
throw new ParentObjectNotFoundException(
"Attempted to delete a request schedule from a cluster which doesn't "
+ "exist", e);
}
RequestExecution requestExecution =
cluster.getAllRequestExecutions().get(request.getId());
if (requestExecution == null) {
throw new AmbariException("Request Schedule not found "
+ ", clusterName = " + request.getClusterName()
+ ", description = " + request.getDescription()
+ ", id = " + request.getId());
}
String username = getManagementController().getAuthName();
LOG.info("Disabling Request Schedule "
+ ", clusterName = " + request.getClusterName()
+ ", id = " + request.getId()
+ ", user = " + username);
// Delete all jobs and triggers
getManagementController().getExecutionScheduleManager()
.deleteAllJobs(requestExecution);
requestExecution.updateStatus(RequestExecution.Status.DISABLED);
} |
223551095_1460 | @Override
public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException,
ResourceAlreadyExistsException, NoSuchParentResourceException {
IvoryService service = getService();
Set<Map<String, Object>> propertiesSet = request.getProperties();
for(Map<String, Object> propertyMap : propertiesSet) {
service.submitCluster(getCluster((String) propertyMap.get(CLUSTER_NAME_PROPERTY_ID), propertyMap));
}
return new RequestStatusImpl(null);
} |
223551095_1461 | @Override
public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException,
UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
IvoryService service = getService();
List<String> clusterNames = service.getClusterNames();
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<Resource> resources = new HashSet<>();
for (String clusterName : clusterNames ) {
Cluster cluster = service.getCluster(clusterName);
Resource resource = new ResourceImpl(Resource.Type.DRTargetCluster);
setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID,
cluster.getName(), requestedIds);
setResourceProperty(resource, CLUSTER_COLO_PROPERTY_ID,
cluster.getColo(), requestedIds);
setResourceProperty(resource, CLUSTER_INTERFACES_PROPERTY_ID,
cluster.getInterfaces(), requestedIds);
setResourceProperty(resource, CLUSTER_LOCATIONS_PROPERTY_ID,
cluster.getLocations(), requestedIds);
setResourceProperty(resource, CLUSTER_PROPERTIES_PROPERTY_ID,
cluster.getProperties(), requestedIds);
if (predicate == null || predicate.evaluate(resource)) {
resources.add(resource);
}
}
return resources;
} |
223551095_1462 | @Override
public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException,
UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
IvoryService service = getService();
Iterator<Map<String,Object>> iterator = request.getProperties().iterator();
if (iterator.hasNext()) {
Map<String, Object> propertyMap = iterator.next();
// get all the clusters that pass the predicate check
Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate);
for (Resource resource : resources) {
// update all the matching clusters with the property values from the request
service.updateCluster(getCluster((String) resource.getPropertyValue(CLUSTER_NAME_PROPERTY_ID), propertyMap));
}
}
return new RequestStatusImpl(null);
} |
223551095_1463 | @Override
public RequestStatus deleteResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
IvoryService service = getService();
// get all the clusters that pass the predicate check
Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate);
for (Resource resource : resources) {
// delete all the matching clusters with the property values from the request
service.deleteCluster((String) resource.getPropertyValue(CLUSTER_NAME_PROPERTY_ID));
}
return new RequestStatusImpl(null);
} |
223551095_1464 | @Override
public QueryResponse getResources(Type type, Request request, Predicate predicate)
throws UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException, SystemException {
QueryResponse queryResponse = null;
ExtendedResourceProviderWrapper provider = ensureResourceProviderWrapper(type);
ensurePropertyProviders(type);
if (provider != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Using resource provider {} for request type {}", provider.getClass().getName(), type);
}
// make sure that the providers can satisfy the request
checkProperties(type, request, predicate);
// get the resources
queryResponse = provider.queryForResources(request, predicate);
}
return queryResponse == null ? new QueryResponseImpl(Collections.emptySet()) : queryResponse;
} |
223551095_1465 | protected Iterable<Resource> getResourceIterable(Type type, Request request,
Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchParentResourceException,
NoSuchResourceException {
return getResources(type, request, predicate, null, null).getIterable();
} |
223551095_1466 | protected Iterable<Resource> getResourceIterable(Type type, Request request,
Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchParentResourceException,
NoSuchResourceException {
return getResources(type, request, predicate, null, null).getIterable();
} |
223551095_1467 | protected Iterable<Resource> getResourceIterable(Type type, Request request,
Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchParentResourceException,
NoSuchResourceException {
return getResources(type, request, predicate, null, null).getIterable();
} |
223551095_1468 | protected Iterable<Resource> getResourceIterable(Type type, Request request,
Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchParentResourceException,
NoSuchResourceException {
return getResources(type, request, predicate, null, null).getIterable();
} |
223551095_1469 | protected Iterable<Resource> getResourceIterable(Type type, Request request,
Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchParentResourceException,
NoSuchResourceException {
return getResources(type, request, predicate, null, null).getIterable();
} |
223551095_1470 | @Override
public RequestStatus createResources(Type type, Request request)
throws UnsupportedPropertyException,
SystemException,
ResourceAlreadyExistsException,
NoSuchParentResourceException {
ResourceProvider provider = ensureResourceProvider(type);
if (provider != null) {
checkProperties(type, request, null);
return provider.createResources(request);
}
return null;
} |
223551095_1471 | @Override
public RequestStatus createResources(Type type, Request request)
throws UnsupportedPropertyException,
SystemException,
ResourceAlreadyExistsException,
NoSuchParentResourceException {
ResourceProvider provider = ensureResourceProvider(type);
if (provider != null) {
checkProperties(type, request, null);
return provider.createResources(request);
}
return null;
} |
223551095_1472 | @Override
public RequestStatus updateResources(Type type, Request request, Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchResourceException,
NoSuchParentResourceException {
ResourceProvider provider = ensureResourceProvider(type);
if (provider != null) {
if (!checkProperties(type, request, predicate)) {
predicate = resolvePredicate(type, predicate);
if (predicate == null) {
return null;
}
}
return provider.updateResources(request, predicate);
}
return null;
} |
223551095_1473 | @Override
public RequestStatus updateResources(Type type, Request request, Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchResourceException,
NoSuchParentResourceException {
ResourceProvider provider = ensureResourceProvider(type);
if (provider != null) {
if (!checkProperties(type, request, predicate)) {
predicate = resolvePredicate(type, predicate);
if (predicate == null) {
return null;
}
}
return provider.updateResources(request, predicate);
}
return null;
} |
223551095_1474 | @Override
public RequestStatus updateResources(Type type, Request request, Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchResourceException,
NoSuchParentResourceException {
ResourceProvider provider = ensureResourceProvider(type);
if (provider != null) {
if (!checkProperties(type, request, predicate)) {
predicate = resolvePredicate(type, predicate);
if (predicate == null) {
return null;
}
}
return provider.updateResources(request, predicate);
}
return null;
} |
223551095_1475 | @Override
public RequestStatus updateResources(Type type, Request request, Predicate predicate)
throws UnsupportedPropertyException,
SystemException,
NoSuchResourceException,
NoSuchParentResourceException {
ResourceProvider provider = ensureResourceProvider(type);
if (provider != null) {
if (!checkProperties(type, request, predicate)) {
predicate = resolvePredicate(type, predicate);
if (predicate == null) {
return null;
}
}
return provider.updateResources(request, predicate);
}
return null;
} |
223551095_1485 | @Override
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
final Set<RootServiceRequest> requests = new HashSet<>();
if (predicate == null) {
requests.add(getRequest(Collections.emptyMap()));
} else {
for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
requests.add(getRequest(propertyMap));
}
}
Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<RootServiceResponse> responses = getResources(new Command<Set<RootServiceResponse>>() {
@Override
public Set<RootServiceResponse> invoke() throws AmbariException {
return getManagementController().getRootServices(requests);
}
});
Set<Resource> resources = new HashSet<>();
for (RootServiceResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.RootService);
setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds);
resources.add(resource);
}
return resources;
} |