public void decRequested() { cancel(1); }
/** * Cancel any outstanding AA Requests, building up the list of ops to * cancel, removing them from RoleHistory structures and the RoleStatus * entries. * @return a (usually empty) list of cancel/request operations. */ public synchronized List<AbstractRMOperation> cancelOutstandingAARequests() { // get the list of cancel operations List<AbstractRMOperation> operations = roleHistory.cancelOutstandingAARequests(); for (RoleStatus roleStatus : roleStatusMap.values()) { if (roleStatus.isAARequestOutstanding()) { log.info("Cancelling outstanding AA request for {}", roleStatus); roleStatus.cancelOutstandingAARequest(); } } return operations; }
/** * Get a deep clone of the role status list. Concurrent events may mean this * list (or indeed, some of the role status entries) may be inconsistent * @return a snapshot of the role status entries */ public List<RoleStatus> cloneRoleStatusList() { Collection<RoleStatus> statuses = roleStatusMap.values(); List<RoleStatus> statusList = new ArrayList<>(statuses.size()); try { for (RoleStatus status : statuses) { statusList.add((RoleStatus)(status.clone())); } } catch (CloneNotSupportedException e) { log.warn("Unexpected cloning failure: {}", e, e); } return statusList; }
String rolename = role.getName(); if (hasUniqueNames(instanceDefinition.getResourceOperations(), role.getGroup())) { cd.setRoleOpt(rolename, COMPONENT_PRIORITY, role.getPriority()); cd.setRoleOpt(rolename, ROLE_GROUP, role.getGroup()); MapOperations groupOptions = instanceDefinition.getResourceOperations() .getComponent(role.getGroup()); SliderUtils.mergeMapsIgnoreDuplicateKeys(cd.getRole(rolename), groupOptions.options); .getComponentOpt(role.getGroup(), ROLE_PREFIX, null); if (SliderUtils.isSet(prefix)) { cd.setRoleOpt(rolename, ROLE_PREFIX, SliderUtils.trimPrefix(prefix)); int nodeCount = instances != null ? instances.size(): 0; cd.setRoleOpt(rolename, COMPONENT_INSTANCES, role.getDesired()); cd.setRoleOpt(rolename, ROLE_ACTUAL_INSTANCES, nodeCount); cd.setRoleOpt(rolename, ROLE_REQUESTED_INSTANCES, role.getRequested()); cd.setRoleOpt(rolename, ROLE_RELEASING_INSTANCES, role.getReleasing()); cd.setRoleOpt(rolename, ROLE_FAILED_INSTANCES, role.getFailed()); cd.setRoleOpt(rolename, ROLE_FAILED_STARTING_INSTANCES, role.getStartFailed()); cd.setRoleOpt(rolename, ROLE_FAILED_RECENTLY_INSTANCES, role.getFailedRecently()); cd.setRoleOpt(rolename, ROLE_NODE_FAILED_INSTANCES, role.getNodeFailed()); cd.setRoleOpt(rolename, ROLE_PREEMPTED_INSTANCES, role.getPreempted()); if (role.isAntiAffinePlacement()) { cd.setRoleOpt(rolename, ROLE_PENDING_AA_INSTANCES, role.getPendingAntiAffineRequests()); Map<String, Integer> stats = role.buildStatistics();
role.decRequested(); final long allocated = role.incActual(); final long desired = role.getDesired(); final String roleName = role.getName(); final ContainerAllocationResults allocation = roleHistory.onContainerAllocated(container, desired, allocated); surplusContainers.inc(); role.decActual(); } else { if (role.isAntiAffinePlacement()) { role.completeOutstandingAARequest(); if (node.canHost(role.getKey(), role.getLabelExpression())) { log.error("Assigned node still declares as available {}", node.toFullString() ); if (role.getPendingAntiAffineRequests() > 0) { log.info("No capacity in cluster for new requests"); } else { role.decPendingAntiAffineRequests();
long delta; long expected; String name = role.getName(); synchronized (role) { delta = role.getDelta(); expected = role.getDesired(); if (!role.isHealthThresholdMonitorEnabled()) { checkFailureThreshold(role); if (role.isAntiAffinePlacement()) { long pending = delta; if (roleHistory.canPlaceAANodes()) { if (!role.isAARequestOutstanding()) { role.setPendingAntiAffineRequests(pending); } else { long outstandingRequests = role.getRequested() + role.getPendingAntiAffineRequests(); if (outstandingRequests > 0) { role.cancel(toCancel); excess -= toCancel; assert excess >= 0 : "Attempted to cancel too many requests"; int roleId = role.getKey(); if (role.getPendingAntiAffineRequests() > 0) {
Container container = containersBeingReleased.remove(containerId); RoleStatus roleStatus = lookupRoleStatus(container); long releasing = roleStatus.decReleasing(); long actual = roleStatus.decActual(); long completedCount = roleStatus.incCompleted(); log.info("decrementing role count for role {} to {}; releasing={}, completed={}", roleStatus.getName(), actual, releasing, try { RoleStatus roleStatus = lookupRoleStatus(roleId); roleStatus.decActual(); boolean shortLived = isShortLived(roleInstance); String message; message = String.format("Failure %s (%d)", containerId, exitStatus); roleStatus.noteFailed(shortLived, message, result.outcome, containerId); long failed = roleStatus.getFailed(); log.info("Current count of failed role[{}] {} = {}", roleId, rolename, failed);
int roleId = role.getKey(); List<OutstandingRequest> requests = new ArrayList<>(toCancel); long pending = role.getPendingAntiAffineRequests(); if (pending > 0) { log.info("Cancelling {} pending AA allocations, leaving {}", toCancel, pendingToCancel); role.setPendingAntiAffineRequests(pending - pendingToCancel); toCancel -= pendingToCancel; if (toCancel > 0 && role.isAARequestOutstanding()) { role.cancelOutstandingAARequest(); toCancel--;
/** * Find a node for an AA role and request an instance on that (or a location-less * instance) * @param role role status * @return a request ready to go, or null if no location can be found. */ public synchronized OutstandingRequest requestContainerForAARole(RoleStatus role) { List<NodeInstance> nodes = findNodeForNewAAInstance(role); if (!nodes.isEmpty()) { OutstandingRequest outstanding = outstandingRequests.newAARequest( role.getKey(), nodes, role.getLabelExpression()); Resource resource = recordFactory.newResource(); role.copyResourceRequirements(resource); outstanding.buildContainerRequest(resource, role, now()); return outstanding; } else { log.warn("No suitable location for {}", role.getName()); return null; } } /**
/** * Find a node for a role and request an instance on that (or a location-less * instance) * @param role role status * @return a request ready to go, or null if this is an AA request and no * location can be found. */ public synchronized OutstandingRequest requestContainerForRole(RoleStatus role) { if (role.isAntiAffinePlacement()) { return requestContainerForAARole(role); } else { Resource resource = recordFactory.newResource(); role.copyResourceRequirements(resource); NodeInstance node = findRecentNodeForNewInstance(role); return requestInstanceOnNode(node, role, resource); } }
/** * Add knowledge of a role. * This is a build-time operation that is not synchronized, and * should be used while setting up the system state -before servicing * requests. * @param providerRole role to add * @return the role status built up * @throws BadConfigException if a role of that priority already exists */ public RoleStatus buildRole(ProviderRole providerRole) throws BadConfigException { // build role status map int priority = providerRole.id; if (roleStatusMap.containsKey(priority)) { throw new BadConfigException("Duplicate Provider Key: %s and %s", providerRole, roleStatusMap.get(priority)); } RoleStatus roleStatus = new RoleStatus(providerRole); roleStatusMap.put(priority, roleStatus); String name = providerRole.name; roles.put(name, providerRole); rolePriorityMap.put(priority, providerRole); // register its entries metricsAndMonitoring.addMetricSet(MetricsConstants.PREFIX_SLIDER_ROLES + name, roleStatus); return roleStatus; }
String rolename = role.getName(); if (hasUniqueNames(instanceDefinition.getResourceOperations(), role.getGroup())) { cd.setRoleOpt(rolename, COMPONENT_PRIORITY, role.getPriority()); cd.setRoleOpt(rolename, ROLE_GROUP, role.getGroup()); MapOperations groupOptions = instanceDefinition.getResourceOperations() .getComponent(role.getGroup()); SliderUtils.mergeMapsIgnoreDuplicateKeys(cd.getRole(rolename), groupOptions.options); .getComponentOpt(role.getGroup(), ROLE_PREFIX, null); if (SliderUtils.isSet(prefix)) { cd.setRoleOpt(rolename, ROLE_PREFIX, SliderUtils.trimPrefix(prefix)); int nodeCount = instances != null ? instances.size(): 0; cd.setRoleOpt(rolename, COMPONENT_INSTANCES, role.getDesired()); cd.setRoleOpt(rolename, ROLE_ACTUAL_INSTANCES, nodeCount); cd.setRoleOpt(rolename, ROLE_REQUESTED_INSTANCES, role.getRequested()); cd.setRoleOpt(rolename, ROLE_RELEASING_INSTANCES, role.getReleasing()); cd.setRoleOpt(rolename, ROLE_FAILED_INSTANCES, role.getFailed()); cd.setRoleOpt(rolename, ROLE_FAILED_STARTING_INSTANCES, role.getStartFailed()); cd.setRoleOpt(rolename, ROLE_FAILED_RECENTLY_INSTANCES, role.getFailedRecently()); cd.setRoleOpt(rolename, ROLE_NODE_FAILED_INSTANCES, role.getNodeFailed()); cd.setRoleOpt(rolename, ROLE_PREEMPTED_INSTANCES, role.getPreempted()); if (role.isAntiAffinePlacement()) { cd.setRoleOpt(rolename, ROLE_PENDING_AA_INSTANCES, role.getPendingAntiAffineRequests()); Map<String, Integer> stats = role.buildStatistics();
role.decRequested(); final long allocated = role.incActual(); final long desired = role.getDesired(); final String roleName = role.getName(); final ContainerAllocationResults allocation = roleHistory.onContainerAllocated(container, desired, allocated); surplusContainers.inc(); role.decActual(); } else { if (role.isAntiAffinePlacement()) { role.completeOutstandingAARequest(); if (node.canHost(role.getKey(), role.getLabelExpression())) { log.error("Assigned node still declares as available {}", node.toFullString() ); if (role.getPendingAntiAffineRequests() > 0) { log.info("No capacity in cluster for new requests"); } else { role.decPendingAntiAffineRequests();
long delta; long expected; String name = role.getName(); synchronized (role) { delta = role.getDelta(); expected = role.getDesired(); if (role.isAntiAffinePlacement()) { long pending = delta; if (roleHistory.canPlaceAANodes()) { if (!role.isAARequestOutstanding()) { role.setPendingAntiAffineRequests(pending); } else { long outstandingRequests = role.getRequested() + role.getPendingAntiAffineRequests(); if (outstandingRequests > 0) { role.cancel(toCancel); excess -= toCancel; assert excess >= 0 : "Attempted to cancel too many requests"; int roleId = role.getKey(); if (role.getPendingAntiAffineRequests() > 0) { log.debug("Clearing outstanding pending AA requests"); role.setPendingAntiAffineRequests(0);
Container container = containersBeingReleased.remove(containerId); RoleStatus roleStatus = lookupRoleStatus(container); long releasing = roleStatus.decReleasing(); long actual = roleStatus.decActual(); long completedCount = roleStatus.incCompleted(); log.info("decrementing role count for role {} to {}; releasing={}, completed={}", roleStatus.getName(), actual, releasing, try { RoleStatus roleStatus = lookupRoleStatus(roleId); roleStatus.decActual(); boolean shortLived = isShortLived(roleInstance); String message; message = String.format("Failure %s (%d)", containerId, exitStatus); roleStatus.noteFailed(shortLived, message, result.outcome, containerId); long failed = roleStatus.getFailed(); log.info("Current count of failed role[{}] {} = {}", roleId, rolename, failed);
int roleId = role.getKey(); List<OutstandingRequest> requests = new ArrayList<>(toCancel); long pending = role.getPendingAntiAffineRequests(); if (pending > 0) { log.info("Cancelling {} pending AA allocations, leaving {}", toCancel, pendingToCancel); role.setPendingAntiAffineRequests(pending - pendingToCancel); toCancel -= pendingToCancel; if (toCancel > 0 && role.isAARequestOutstanding()) { role.cancelOutstandingAARequest(); toCancel--;
/** * Find a node for an AA role and request an instance on that (or a location-less * instance) * @param role role status * @return a request ready to go, or null if no location can be found. */ public synchronized OutstandingRequest requestContainerForAARole(RoleStatus role) { List<NodeInstance> nodes = findNodeForNewAAInstance(role); if (!nodes.isEmpty()) { OutstandingRequest outstanding = outstandingRequests.newAARequest( role.getKey(), nodes, role.getLabelExpression()); Resource resource = recordFactory.newResource(); role.copyResourceRequirements(resource); outstanding.buildContainerRequest(resource, role, now()); return outstanding; } else { log.warn("No suitable location for {}", role.getName()); return null; } } /**
/** * Find a node for a role and request an instance on that (or a location-less * instance) * @param role role status * @return a request ready to go, or null if this is an AA request and no * location can be found. */ public synchronized OutstandingRequest requestContainerForRole(RoleStatus role) { if (role.isAntiAffinePlacement()) { return requestContainerForAARole(role); } else { Resource resource = recordFactory.newResource(); role.copyResourceRequirements(resource); NodeInstance node = findRecentNodeForNewInstance(role); return requestInstanceOnNode(node, role, resource); } }
/** * Add knowledge of a role. * This is a build-time operation that is not synchronized, and * should be used while setting up the system state -before servicing * requests. * @param providerRole role to add * @return the role status built up * @throws BadConfigException if a role of that priority already exists */ public RoleStatus buildRole(ProviderRole providerRole) throws BadConfigException { // build role status map int priority = providerRole.id; if (roleStatusMap.containsKey(priority)) { throw new BadConfigException("Duplicate Provider Key: %s and %s", providerRole, roleStatusMap.get(priority)); } RoleStatus roleStatus = new RoleStatus(providerRole); roleStatusMap.put(priority, roleStatus); String name = providerRole.name; roles.put(name, providerRole); rolePriorityMap.put(priority, providerRole); // register its entries metricsAndMonitoring.addMetricSet(MetricsConstants.PREFIX_SLIDER_ROLES + name, roleStatus); return roleStatus; }
/** * Cancel any outstanding AA Requests, building up the list of ops to * cancel, removing them from RoleHistory structures and the RoleStatus * entries. * @return a (usually empty) list of cancel/request operations. */ public synchronized List<AbstractRMOperation> cancelOutstandingAARequests() { // get the list of cancel operations List<AbstractRMOperation> operations = roleHistory.cancelOutstandingAARequests(); for (RoleStatus roleStatus : roleStatusMap.values()) { if (roleStatus.isAARequestOutstanding()) { log.info("Cancelling outstanding AA request for {}", roleStatus); roleStatus.cancelOutstandingAARequest(); } } return operations; }