@Test public void testMeetsExcludeWithMatching() throws ProvisionException { ProvisionRequest request = createProvisionRequest(); request.getServiceElement().setServiceLevelAgreements(createClusterServiceLevelAgreements(true, "10.0.1.33")); assertTrue(instantiatorResource.canProvision(request)); }
public boolean canProvision(final ProvisionRequest provisionRequest) throws ProvisionException { ServiceElement sElem = provisionRequest.getServiceElement(); if (sElem.getPlanned() == 0) { return false; } String provType = sElem.getProvisionType().toString(); if (getServiceElementCount() == serviceLimit.get() && !provType.equals(ServiceElement.ProvisionType.FIXED.toString())) { String failureReason = String.format("%s not selected to allocate service [%s], it has reached it's service limit of [%d]", getName(), LoggingUtil.getLoggingName(sElem), serviceLimit.get()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (sElem.getMaxPerMachine()!=-1) { int serviceCount = getServiceElementCount(sElem); int inProcessCount = getInProcessCounter(sElem); int numInstances = serviceCount+inProcessCount; if (numInstances >= sElem.getMaxPerMachine()) { String failureReason = String.format("%s not selected to allocate service [%s], declaration specifies no more than %d services per machine, found %d", getName(), LoggingUtil.getLoggingName(sElem), sElem.getMaxPerMachine(), numInstances); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } } if (sElem.getProvisionType() == ServiceElement.ProvisionType.FIXED) { int planned = sElem.getPlanned(); int actual = getServiceElementCount(sElem)+getInProcessCounter(sElem); int numAllowed = planned-actual; if (numAllowed <= 0) { String failureReason = String.format("Do not allocate %s service [%s] to %s has [%d] instance(s), planned [%d]", provType, LoggingUtil.getLoggingName(sElem), getName(), actual, planned); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } else { String failureReason = String.format("%s has [%d] instance(s), planned [%d] of %s service [%s]", getName(), actual, planned, provType, LoggingUtil.getLoggingName(sElem)); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); } } if (!AssociationMatcher.meetsColocationRequirements(sElem, this)) { StringBuilder b = new StringBuilder(); b.append(getName()).append(" not selected to allocate ").append(LoggingUtil.getLoggingName(sElem)); b.append(", required colocated services not present: "); AssociationDescriptor[] aDesc = ServiceElementUtil.getAssociationDescriptors(sElem, AssociationType.COLOCATED); int found = 0; for (AssociationDescriptor anADesc : aDesc) { if (found > 0) b.append(", "); found++; b.append(anADesc.getName()); } String failureReason = b.toString(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!AssociationMatcher.meetsOpposedRequirements(sElem, this)) { String failureReason = AssociationMatcher.getLastErrorMessage(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!resourceCapability.measuredResourcesWithinRange()) { StringBuilder buffer = new StringBuilder(); MeasuredResource[] m = resourceCapability.getMeasuredResources(ResourceCapability.MEASURED_RESOURCES_BREACHED); for (MeasuredResource aM : m) { buffer.append("\n"); buffer.append("[").append(aM.getIdentifier()).append("] "); buffer.append("Low: ").append(aM.getThresholdValues().getLowThreshold()).append(", "); buffer.append("High: ").append(aM.getThresholdValues().getHighThreshold()).append(", "); buffer.append("Actual: ").append(aM.getValue()); } String failureReason = String.format("%s not selected to allocate service [%s], MeasuredResources have exceeded threshold constraints: %s", getName(), LoggingUtil.getLoggingName(sElem), buffer.toString()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (meetsGeneralRequirements(provisionRequest) && meetsQuantitativeRequirements(provisionRequest)) { Collection<SystemComponent> unsupportedReqs = meetsQualitativeRequirements(provisionRequest); if (unsupportedReqs.isEmpty()) { logger.debug("{} meets qualitative requirements for [{}]", getName(), LoggingUtil.getLoggingName(sElem)); return true; } else { int x = 0; StringBuilder buffer = new StringBuilder(); for (SystemComponent unsupportedReq : unsupportedReqs) { if (x > 0) buffer.append(", "); buffer.append("[").append(unsupportedReq.toString()).append("]"); x++; } String unsupportedReqsString = buffer.toString(); logger.debug("{} does not meet requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); if (!resourceCapability.supportsPersistentProvisioning()) { String failureReason = String.format("Cannot allocate %s service [%s] to %s, required SystemComponents cannot be " + "provisioned. This is because the %s is not configured for persistentProvisioning. " + "If you want to enable this feature, verify the %s's configuration for the " + "org.rioproject.cybernode.persistentProvisioning property is set to true", provType, LoggingUtil.getLoggingName(sElem), getName(), getName(), getName()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } boolean provisionableCaps = true; for (SystemComponent sysReq : unsupportedReqs) { if (sysReq.getStagedSoftware()==null) { provisionableCaps = false; break; } } if (!provisionableCaps) { String failureReason = getName() + " does not meet requirements for " + provType + " service " + "[" + LoggingUtil.getLoggingName(sElem) + "] " + unsupportedReqsString; provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } long requiredSize = 0; IOException failed = null; try { for (SystemComponent sysReq : unsupportedReqs) { StagedSoftware download = sysReq.getStagedSoftware(); if (download != null) { long size = download.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for {}, received {}, abort provision request", download.getLocation(), size); requiredSize = size; break; } requiredSize += size; if (download.getPostInstallAttributes() != null && download.getPostInstallAttributes().getStagedData() != null) { StagedData postInstall = download.getPostInstallAttributes().getStagedData(); size = postInstall.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for PostInstall {}, abort provision request", postInstall.getLocation()); requiredSize = size; break; } requiredSize += size; } } } } catch(IOException e) { failed = e; } if (requiredSize < 0 || failed != null) throw new ProvisionException("Service ["+LoggingUtil.getLoggingName(sElem)+"] "+ "instantiation failed", failed == null? new IOException("Unable to obtain download size"):failed, true); if (supportsStorageRequirement(requiredSize, resourceCapability.getPlatformCapabilities())) { logger.debug("{} supports provisioning requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); sElem.setProvisionablePlatformCapabilities(unsupportedReqs); return true; } double avail = getAvailableStorage(resourceCapability.getPlatformCapabilities()); StringBuilder sb = new StringBuilder(); sb.append(getName()).append(" "); if (avail>0) { double GB = Math.pow(1024, 3); avail = avail/GB; sb.append("does not have adequate disk-space for ") .append("[") .append(LoggingUtil.getLoggingName(sElem)).append("] ") .append("Required=") .append(+requiredSize).append(", ") .append("Available=").append(avail).append(" GB"); } else { sb.append("does not report a StorageCapability. ") .append("Rio cannot allocate the ") .append("[") .append(LoggingUtil.getLoggingName(sElem)) .append("] ") .append("service with a software download size of ") .append(+requiredSize).append(". ") .append("This may be due to a known limitation ") .append("found when running the ").append(getName()) .append(" on a Windows machine, or if the ") .append("DiskSpace monitor has been disabled. ") .append("Check the Cybernode environment and ") .append("configuration."); } String failureReason = sb.toString(); provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } } else { String failureReason = String.format("%s does not meet general or quantitative requirements for %s service [%s]", getName(), provType, LoggingUtil.getLoggingName(sElem)); logger.debug(failureReason); return false; } }
InstantiatorResource { public boolean canProvision(final ProvisionRequest provisionRequest) throws ProvisionException { ServiceElement sElem = provisionRequest.getServiceElement(); if (sElem.getPlanned() == 0) { return false; } String provType = sElem.getProvisionType().toString(); if (getServiceElementCount() == serviceLimit.get() && !provType.equals(ServiceElement.ProvisionType.FIXED.toString())) { String failureReason = String.format("%s not selected to allocate service [%s], it has reached it's service limit of [%d]", getName(), LoggingUtil.getLoggingName(sElem), serviceLimit.get()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (sElem.getMaxPerMachine()!=-1) { int serviceCount = getServiceElementCount(sElem); int inProcessCount = getInProcessCounter(sElem); int numInstances = serviceCount+inProcessCount; if (numInstances >= sElem.getMaxPerMachine()) { String failureReason = String.format("%s not selected to allocate service [%s], declaration specifies no more than %d services per machine, found %d", getName(), LoggingUtil.getLoggingName(sElem), sElem.getMaxPerMachine(), numInstances); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } } if (sElem.getProvisionType() == ServiceElement.ProvisionType.FIXED) { int planned = sElem.getPlanned(); int actual = getServiceElementCount(sElem)+getInProcessCounter(sElem); int numAllowed = planned-actual; if (numAllowed <= 0) { String failureReason = String.format("Do not allocate %s service [%s] to %s has [%d] instance(s), planned [%d]", provType, LoggingUtil.getLoggingName(sElem), getName(), actual, planned); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } else { String failureReason = String.format("%s has [%d] instance(s), planned [%d] of %s service [%s]", getName(), actual, planned, provType, LoggingUtil.getLoggingName(sElem)); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); } } if (!AssociationMatcher.meetsColocationRequirements(sElem, this)) { StringBuilder b = new StringBuilder(); b.append(getName()).append(" not selected to allocate ").append(LoggingUtil.getLoggingName(sElem)); b.append(", required colocated services not present: "); AssociationDescriptor[] aDesc = ServiceElementUtil.getAssociationDescriptors(sElem, AssociationType.COLOCATED); int found = 0; for (AssociationDescriptor anADesc : aDesc) { if (found > 0) b.append(", "); found++; b.append(anADesc.getName()); } String failureReason = b.toString(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!AssociationMatcher.meetsOpposedRequirements(sElem, this)) { String failureReason = AssociationMatcher.getLastErrorMessage(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!resourceCapability.measuredResourcesWithinRange()) { StringBuilder buffer = new StringBuilder(); MeasuredResource[] m = resourceCapability.getMeasuredResources(ResourceCapability.MEASURED_RESOURCES_BREACHED); for (MeasuredResource aM : m) { buffer.append("\n"); buffer.append("[").append(aM.getIdentifier()).append("] "); buffer.append("Low: ").append(aM.getThresholdValues().getLowThreshold()).append(", "); buffer.append("High: ").append(aM.getThresholdValues().getHighThreshold()).append(", "); buffer.append("Actual: ").append(aM.getValue()); } String failureReason = String.format("%s not selected to allocate service [%s], MeasuredResources have exceeded threshold constraints: %s", getName(), LoggingUtil.getLoggingName(sElem), buffer.toString()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (meetsGeneralRequirements(provisionRequest) && meetsQuantitativeRequirements(provisionRequest)) { Collection<SystemComponent> unsupportedReqs = meetsQualitativeRequirements(provisionRequest); if (unsupportedReqs.isEmpty()) { logger.debug("{} meets qualitative requirements for [{}]", getName(), LoggingUtil.getLoggingName(sElem)); return true; } else { int x = 0; StringBuilder buffer = new StringBuilder(); for (SystemComponent unsupportedReq : unsupportedReqs) { if (x > 0) buffer.append(", "); buffer.append("[").append(unsupportedReq.toString()).append("]"); x++; } String unsupportedReqsString = buffer.toString(); logger.debug("{} does not meet requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); if (!resourceCapability.supportsPersistentProvisioning()) { String failureReason = String.format("Cannot allocate %s service [%s] to %s, required SystemComponents cannot be " + "provisioned. This is because the %s is not configured for persistentProvisioning. " + "If you want to enable this feature, verify the %s's configuration for the " + "org.rioproject.cybernode.persistentProvisioning property is set to true", provType, LoggingUtil.getLoggingName(sElem), getName(), getName(), getName()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } boolean provisionableCaps = true; for (SystemComponent sysReq : unsupportedReqs) { if (sysReq.getStagedSoftware()==null) { provisionableCaps = false; break; } } if (!provisionableCaps) { String failureReason = getName() + " does not meet requirements for " + provType + " service " + "[" + LoggingUtil.getLoggingName(sElem) + "] " + unsupportedReqsString; provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } long requiredSize = 0; IOException failed = null; try { for (SystemComponent sysReq : unsupportedReqs) { StagedSoftware download = sysReq.getStagedSoftware(); if (download != null) { long size = download.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for {}, received {}, abort provision request", download.getLocation(), size); requiredSize = size; break; } requiredSize += size; if (download.getPostInstallAttributes() != null && download.getPostInstallAttributes().getStagedData() != null) { StagedData postInstall = download.getPostInstallAttributes().getStagedData(); size = postInstall.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for PostInstall {}, abort provision request", postInstall.getLocation()); requiredSize = size; break; } requiredSize += size; } } } } catch(IOException e) { failed = e; } if (requiredSize < 0 || failed != null) throw new ProvisionException("Service ["+LoggingUtil.getLoggingName(sElem)+"] "+ "instantiation failed", failed == null? new IOException("Unable to obtain download size"):failed, true); if (supportsStorageRequirement(requiredSize, resourceCapability.getPlatformCapabilities())) { logger.debug("{} supports provisioning requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); sElem.setProvisionablePlatformCapabilities(unsupportedReqs); return true; } double avail = getAvailableStorage(resourceCapability.getPlatformCapabilities()); StringBuilder sb = new StringBuilder(); sb.append(getName()).append(" "); if (avail>0) { double GB = Math.pow(1024, 3); avail = avail/GB; sb.append("does not have adequate disk-space for ") .append("[") .append(LoggingUtil.getLoggingName(sElem)).append("] ") .append("Required=") .append(+requiredSize).append(", ") .append("Available=").append(avail).append(" GB"); } else { sb.append("does not report a StorageCapability. ") .append("Rio cannot allocate the ") .append("[") .append(LoggingUtil.getLoggingName(sElem)) .append("] ") .append("service with a software download size of ") .append(+requiredSize).append(". ") .append("This may be due to a known limitation ") .append("found when running the ").append(getName()) .append(" on a Windows machine, or if the ") .append("DiskSpace monitor has been disabled. ") .append("Check the Cybernode environment and ") .append("configuration."); } String failureReason = sb.toString(); provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } } else { String failureReason = String.format("%s does not meet general or quantitative requirements for %s service [%s]", getName(), provType, LoggingUtil.getLoggingName(sElem)); logger.debug(failureReason); return false; } } }
InstantiatorResource { public boolean canProvision(final ProvisionRequest provisionRequest) throws ProvisionException { ServiceElement sElem = provisionRequest.getServiceElement(); if (sElem.getPlanned() == 0) { return false; } String provType = sElem.getProvisionType().toString(); if (getServiceElementCount() == serviceLimit.get() && !provType.equals(ServiceElement.ProvisionType.FIXED.toString())) { String failureReason = String.format("%s not selected to allocate service [%s], it has reached it's service limit of [%d]", getName(), LoggingUtil.getLoggingName(sElem), serviceLimit.get()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (sElem.getMaxPerMachine()!=-1) { int serviceCount = getServiceElementCount(sElem); int inProcessCount = getInProcessCounter(sElem); int numInstances = serviceCount+inProcessCount; if (numInstances >= sElem.getMaxPerMachine()) { String failureReason = String.format("%s not selected to allocate service [%s], declaration specifies no more than %d services per machine, found %d", getName(), LoggingUtil.getLoggingName(sElem), sElem.getMaxPerMachine(), numInstances); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } } if (sElem.getProvisionType() == ServiceElement.ProvisionType.FIXED) { int planned = sElem.getPlanned(); int actual = getServiceElementCount(sElem)+getInProcessCounter(sElem); int numAllowed = planned-actual; if (numAllowed <= 0) { String failureReason = String.format("Do not allocate %s service [%s] to %s has [%d] instance(s), planned [%d]", provType, LoggingUtil.getLoggingName(sElem), getName(), actual, planned); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } else { String failureReason = String.format("%s has [%d] instance(s), planned [%d] of %s service [%s]", getName(), actual, planned, provType, LoggingUtil.getLoggingName(sElem)); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); } } if (!AssociationMatcher.meetsColocationRequirements(sElem, this)) { StringBuilder b = new StringBuilder(); b.append(getName()).append(" not selected to allocate ").append(LoggingUtil.getLoggingName(sElem)); b.append(", required colocated services not present: "); AssociationDescriptor[] aDesc = ServiceElementUtil.getAssociationDescriptors(sElem, AssociationType.COLOCATED); int found = 0; for (AssociationDescriptor anADesc : aDesc) { if (found > 0) b.append(", "); found++; b.append(anADesc.getName()); } String failureReason = b.toString(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!AssociationMatcher.meetsOpposedRequirements(sElem, this)) { String failureReason = AssociationMatcher.getLastErrorMessage(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!resourceCapability.measuredResourcesWithinRange()) { StringBuilder buffer = new StringBuilder(); MeasuredResource[] m = resourceCapability.getMeasuredResources(ResourceCapability.MEASURED_RESOURCES_BREACHED); for (MeasuredResource aM : m) { buffer.append("\n"); buffer.append("[").append(aM.getIdentifier()).append("] "); buffer.append("Low: ").append(aM.getThresholdValues().getLowThreshold()).append(", "); buffer.append("High: ").append(aM.getThresholdValues().getHighThreshold()).append(", "); buffer.append("Actual: ").append(aM.getValue()); } String failureReason = String.format("%s not selected to allocate service [%s], MeasuredResources have exceeded threshold constraints: %s", getName(), LoggingUtil.getLoggingName(sElem), buffer.toString()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (meetsGeneralRequirements(provisionRequest) && meetsQuantitativeRequirements(provisionRequest)) { Collection<SystemComponent> unsupportedReqs = meetsQualitativeRequirements(provisionRequest); if (unsupportedReqs.isEmpty()) { logger.debug("{} meets qualitative requirements for [{}]", getName(), LoggingUtil.getLoggingName(sElem)); return true; } else { int x = 0; StringBuilder buffer = new StringBuilder(); for (SystemComponent unsupportedReq : unsupportedReqs) { if (x > 0) buffer.append(", "); buffer.append("[").append(unsupportedReq.toString()).append("]"); x++; } String unsupportedReqsString = buffer.toString(); logger.debug("{} does not meet requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); if (!resourceCapability.supportsPersistentProvisioning()) { String failureReason = String.format("Cannot allocate %s service [%s] to %s, required SystemComponents cannot be " + "provisioned. This is because the %s is not configured for persistentProvisioning. " + "If you want to enable this feature, verify the %s's configuration for the " + "org.rioproject.cybernode.persistentProvisioning property is set to true", provType, LoggingUtil.getLoggingName(sElem), getName(), getName(), getName()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } boolean provisionableCaps = true; for (SystemComponent sysReq : unsupportedReqs) { if (sysReq.getStagedSoftware()==null) { provisionableCaps = false; break; } } if (!provisionableCaps) { String failureReason = getName() + " does not meet requirements for " + provType + " service " + "[" + LoggingUtil.getLoggingName(sElem) + "] " + unsupportedReqsString; provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } long requiredSize = 0; IOException failed = null; try { for (SystemComponent sysReq : unsupportedReqs) { StagedSoftware download = sysReq.getStagedSoftware(); if (download != null) { long size = download.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for {}, received {}, abort provision request", download.getLocation(), size); requiredSize = size; break; } requiredSize += size; if (download.getPostInstallAttributes() != null && download.getPostInstallAttributes().getStagedData() != null) { StagedData postInstall = download.getPostInstallAttributes().getStagedData(); size = postInstall.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for PostInstall {}, abort provision request", postInstall.getLocation()); requiredSize = size; break; } requiredSize += size; } } } } catch(IOException e) { failed = e; } if (requiredSize < 0 || failed != null) throw new ProvisionException("Service ["+LoggingUtil.getLoggingName(sElem)+"] "+ "instantiation failed", failed == null? new IOException("Unable to obtain download size"):failed, true); if (supportsStorageRequirement(requiredSize, resourceCapability.getPlatformCapabilities())) { logger.debug("{} supports provisioning requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); sElem.setProvisionablePlatformCapabilities(unsupportedReqs); return true; } double avail = getAvailableStorage(resourceCapability.getPlatformCapabilities()); StringBuilder sb = new StringBuilder(); sb.append(getName()).append(" "); if (avail>0) { double GB = Math.pow(1024, 3); avail = avail/GB; sb.append("does not have adequate disk-space for ") .append("[") .append(LoggingUtil.getLoggingName(sElem)).append("] ") .append("Required=") .append(+requiredSize).append(", ") .append("Available=").append(avail).append(" GB"); } else { sb.append("does not report a StorageCapability. ") .append("Rio cannot allocate the ") .append("[") .append(LoggingUtil.getLoggingName(sElem)) .append("] ") .append("service with a software download size of ") .append(+requiredSize).append(". ") .append("This may be due to a known limitation ") .append("found when running the ").append(getName()) .append(" on a Windows machine, or if the ") .append("DiskSpace monitor has been disabled. ") .append("Check the Cybernode environment and ") .append("configuration."); } String failureReason = sb.toString(); provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } } else { String failureReason = String.format("%s does not meet general or quantitative requirements for %s service [%s]", getName(), provType, LoggingUtil.getLoggingName(sElem)); logger.debug(failureReason); return false; } } InstantiatorResource(MarshalledObject<ServiceBeanInstantiator> wrappedServiceBeanInstantiator,
                                ServiceBeanInstantiator instantiator,
                                String instantiatorName,
                                Uuid instantiatorUuid,
                                MarshalledObject<?> handback,
                                ResourceCapability resourceCapability,
                                int serviceLimit); }
InstantiatorResource { public boolean canProvision(final ProvisionRequest provisionRequest) throws ProvisionException { ServiceElement sElem = provisionRequest.getServiceElement(); if (sElem.getPlanned() == 0) { return false; } String provType = sElem.getProvisionType().toString(); if (getServiceElementCount() == serviceLimit.get() && !provType.equals(ServiceElement.ProvisionType.FIXED.toString())) { String failureReason = String.format("%s not selected to allocate service [%s], it has reached it's service limit of [%d]", getName(), LoggingUtil.getLoggingName(sElem), serviceLimit.get()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (sElem.getMaxPerMachine()!=-1) { int serviceCount = getServiceElementCount(sElem); int inProcessCount = getInProcessCounter(sElem); int numInstances = serviceCount+inProcessCount; if (numInstances >= sElem.getMaxPerMachine()) { String failureReason = String.format("%s not selected to allocate service [%s], declaration specifies no more than %d services per machine, found %d", getName(), LoggingUtil.getLoggingName(sElem), sElem.getMaxPerMachine(), numInstances); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } } if (sElem.getProvisionType() == ServiceElement.ProvisionType.FIXED) { int planned = sElem.getPlanned(); int actual = getServiceElementCount(sElem)+getInProcessCounter(sElem); int numAllowed = planned-actual; if (numAllowed <= 0) { String failureReason = String.format("Do not allocate %s service [%s] to %s has [%d] instance(s), planned [%d]", provType, LoggingUtil.getLoggingName(sElem), getName(), actual, planned); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } else { String failureReason = String.format("%s has [%d] instance(s), planned [%d] of %s service [%s]", getName(), actual, planned, provType, LoggingUtil.getLoggingName(sElem)); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); } } if (!AssociationMatcher.meetsColocationRequirements(sElem, this)) { StringBuilder b = new StringBuilder(); b.append(getName()).append(" not selected to allocate ").append(LoggingUtil.getLoggingName(sElem)); b.append(", required colocated services not present: "); AssociationDescriptor[] aDesc = ServiceElementUtil.getAssociationDescriptors(sElem, AssociationType.COLOCATED); int found = 0; for (AssociationDescriptor anADesc : aDesc) { if (found > 0) b.append(", "); found++; b.append(anADesc.getName()); } String failureReason = b.toString(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!AssociationMatcher.meetsOpposedRequirements(sElem, this)) { String failureReason = AssociationMatcher.getLastErrorMessage(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!resourceCapability.measuredResourcesWithinRange()) { StringBuilder buffer = new StringBuilder(); MeasuredResource[] m = resourceCapability.getMeasuredResources(ResourceCapability.MEASURED_RESOURCES_BREACHED); for (MeasuredResource aM : m) { buffer.append("\n"); buffer.append("[").append(aM.getIdentifier()).append("] "); buffer.append("Low: ").append(aM.getThresholdValues().getLowThreshold()).append(", "); buffer.append("High: ").append(aM.getThresholdValues().getHighThreshold()).append(", "); buffer.append("Actual: ").append(aM.getValue()); } String failureReason = String.format("%s not selected to allocate service [%s], MeasuredResources have exceeded threshold constraints: %s", getName(), LoggingUtil.getLoggingName(sElem), buffer.toString()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (meetsGeneralRequirements(provisionRequest) && meetsQuantitativeRequirements(provisionRequest)) { Collection<SystemComponent> unsupportedReqs = meetsQualitativeRequirements(provisionRequest); if (unsupportedReqs.isEmpty()) { logger.debug("{} meets qualitative requirements for [{}]", getName(), LoggingUtil.getLoggingName(sElem)); return true; } else { int x = 0; StringBuilder buffer = new StringBuilder(); for (SystemComponent unsupportedReq : unsupportedReqs) { if (x > 0) buffer.append(", "); buffer.append("[").append(unsupportedReq.toString()).append("]"); x++; } String unsupportedReqsString = buffer.toString(); logger.debug("{} does not meet requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); if (!resourceCapability.supportsPersistentProvisioning()) { String failureReason = String.format("Cannot allocate %s service [%s] to %s, required SystemComponents cannot be " + "provisioned. This is because the %s is not configured for persistentProvisioning. " + "If you want to enable this feature, verify the %s's configuration for the " + "org.rioproject.cybernode.persistentProvisioning property is set to true", provType, LoggingUtil.getLoggingName(sElem), getName(), getName(), getName()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } boolean provisionableCaps = true; for (SystemComponent sysReq : unsupportedReqs) { if (sysReq.getStagedSoftware()==null) { provisionableCaps = false; break; } } if (!provisionableCaps) { String failureReason = getName() + " does not meet requirements for " + provType + " service " + "[" + LoggingUtil.getLoggingName(sElem) + "] " + unsupportedReqsString; provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } long requiredSize = 0; IOException failed = null; try { for (SystemComponent sysReq : unsupportedReqs) { StagedSoftware download = sysReq.getStagedSoftware(); if (download != null) { long size = download.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for {}, received {}, abort provision request", download.getLocation(), size); requiredSize = size; break; } requiredSize += size; if (download.getPostInstallAttributes() != null && download.getPostInstallAttributes().getStagedData() != null) { StagedData postInstall = download.getPostInstallAttributes().getStagedData(); size = postInstall.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for PostInstall {}, abort provision request", postInstall.getLocation()); requiredSize = size; break; } requiredSize += size; } } } } catch(IOException e) { failed = e; } if (requiredSize < 0 || failed != null) throw new ProvisionException("Service ["+LoggingUtil.getLoggingName(sElem)+"] "+ "instantiation failed", failed == null? new IOException("Unable to obtain download size"):failed, true); if (supportsStorageRequirement(requiredSize, resourceCapability.getPlatformCapabilities())) { logger.debug("{} supports provisioning requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); sElem.setProvisionablePlatformCapabilities(unsupportedReqs); return true; } double avail = getAvailableStorage(resourceCapability.getPlatformCapabilities()); StringBuilder sb = new StringBuilder(); sb.append(getName()).append(" "); if (avail>0) { double GB = Math.pow(1024, 3); avail = avail/GB; sb.append("does not have adequate disk-space for ") .append("[") .append(LoggingUtil.getLoggingName(sElem)).append("] ") .append("Required=") .append(+requiredSize).append(", ") .append("Available=").append(avail).append(" GB"); } else { sb.append("does not report a StorageCapability. ") .append("Rio cannot allocate the ") .append("[") .append(LoggingUtil.getLoggingName(sElem)) .append("] ") .append("service with a software download size of ") .append(+requiredSize).append(". ") .append("This may be due to a known limitation ") .append("found when running the ").append(getName()) .append(" on a Windows machine, or if the ") .append("DiskSpace monitor has been disabled. ") .append("Check the Cybernode environment and ") .append("configuration."); } String failureReason = sb.toString(); provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } } else { String failureReason = String.format("%s does not meet general or quantitative requirements for %s service [%s]", getName(), provType, LoggingUtil.getLoggingName(sElem)); logger.debug(failureReason); return false; } } InstantiatorResource(MarshalledObject<ServiceBeanInstantiator> wrappedServiceBeanInstantiator,
                                ServiceBeanInstantiator instantiator,
                                String instantiatorName,
                                Uuid instantiatorUuid,
                                MarshalledObject<?> handback,
                                ResourceCapability resourceCapability,
                                int serviceLimit); void addDeployedService(DeployedService newDeployedService); String getName(); Uuid getInstantiatorUuid(); int getServiceElementCount(ServiceElement sElem); int getServiceElementCount(); ServiceBeanInstantiator getInstantiator(); int getServiceCount(); MarshalledObject<?> getHandback(); ResourceCapability getResourceCapability(); int getServiceLimit(); void incrementProvisionCounter(ServiceElement sElem); synchronized void decrementProvisionCounter(ServiceElement sElem); int getInProcessCounter(); int getInProcessCounter(ServiceElement sElem); String getHostAddress(); void addUninstantiable(ServiceElement serviceElement); boolean isUninstantiable(ServiceElement serviceElement); void removeUninstantiable(ServiceElement serviceElement); void setDynamicEnabledOn(); boolean getDynamicEnabled(); boolean canProvision(final ProvisionRequest provisionRequest); @Override boolean equals(Object o); @Override int hashCode(); }
InstantiatorResource { public boolean canProvision(final ProvisionRequest provisionRequest) throws ProvisionException { ServiceElement sElem = provisionRequest.getServiceElement(); if (sElem.getPlanned() == 0) { return false; } String provType = sElem.getProvisionType().toString(); if (getServiceElementCount() == serviceLimit.get() && !provType.equals(ServiceElement.ProvisionType.FIXED.toString())) { String failureReason = String.format("%s not selected to allocate service [%s], it has reached it's service limit of [%d]", getName(), LoggingUtil.getLoggingName(sElem), serviceLimit.get()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (sElem.getMaxPerMachine()!=-1) { int serviceCount = getServiceElementCount(sElem); int inProcessCount = getInProcessCounter(sElem); int numInstances = serviceCount+inProcessCount; if (numInstances >= sElem.getMaxPerMachine()) { String failureReason = String.format("%s not selected to allocate service [%s], declaration specifies no more than %d services per machine, found %d", getName(), LoggingUtil.getLoggingName(sElem), sElem.getMaxPerMachine(), numInstances); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } } if (sElem.getProvisionType() == ServiceElement.ProvisionType.FIXED) { int planned = sElem.getPlanned(); int actual = getServiceElementCount(sElem)+getInProcessCounter(sElem); int numAllowed = planned-actual; if (numAllowed <= 0) { String failureReason = String.format("Do not allocate %s service [%s] to %s has [%d] instance(s), planned [%d]", provType, LoggingUtil.getLoggingName(sElem), getName(), actual, planned); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } else { String failureReason = String.format("%s has [%d] instance(s), planned [%d] of %s service [%s]", getName(), actual, planned, provType, LoggingUtil.getLoggingName(sElem)); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); } } if (!AssociationMatcher.meetsColocationRequirements(sElem, this)) { StringBuilder b = new StringBuilder(); b.append(getName()).append(" not selected to allocate ").append(LoggingUtil.getLoggingName(sElem)); b.append(", required colocated services not present: "); AssociationDescriptor[] aDesc = ServiceElementUtil.getAssociationDescriptors(sElem, AssociationType.COLOCATED); int found = 0; for (AssociationDescriptor anADesc : aDesc) { if (found > 0) b.append(", "); found++; b.append(anADesc.getName()); } String failureReason = b.toString(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!AssociationMatcher.meetsOpposedRequirements(sElem, this)) { String failureReason = AssociationMatcher.getLastErrorMessage(); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (!resourceCapability.measuredResourcesWithinRange()) { StringBuilder buffer = new StringBuilder(); MeasuredResource[] m = resourceCapability.getMeasuredResources(ResourceCapability.MEASURED_RESOURCES_BREACHED); for (MeasuredResource aM : m) { buffer.append("\n"); buffer.append("[").append(aM.getIdentifier()).append("] "); buffer.append("Low: ").append(aM.getThresholdValues().getLowThreshold()).append(", "); buffer.append("High: ").append(aM.getThresholdValues().getHighThreshold()).append(", "); buffer.append("Actual: ").append(aM.getValue()); } String failureReason = String.format("%s not selected to allocate service [%s], MeasuredResources have exceeded threshold constraints: %s", getName(), LoggingUtil.getLoggingName(sElem), buffer.toString()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } if (meetsGeneralRequirements(provisionRequest) && meetsQuantitativeRequirements(provisionRequest)) { Collection<SystemComponent> unsupportedReqs = meetsQualitativeRequirements(provisionRequest); if (unsupportedReqs.isEmpty()) { logger.debug("{} meets qualitative requirements for [{}]", getName(), LoggingUtil.getLoggingName(sElem)); return true; } else { int x = 0; StringBuilder buffer = new StringBuilder(); for (SystemComponent unsupportedReq : unsupportedReqs) { if (x > 0) buffer.append(", "); buffer.append("[").append(unsupportedReq.toString()).append("]"); x++; } String unsupportedReqsString = buffer.toString(); logger.debug("{} does not meet requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); if (!resourceCapability.supportsPersistentProvisioning()) { String failureReason = String.format("Cannot allocate %s service [%s] to %s, required SystemComponents cannot be " + "provisioned. This is because the %s is not configured for persistentProvisioning. " + "If you want to enable this feature, verify the %s's configuration for the " + "org.rioproject.cybernode.persistentProvisioning property is set to true", provType, LoggingUtil.getLoggingName(sElem), getName(), getName(), getName()); provisionRequest.addFailureReason(failureReason); logger.debug(failureReason); return false; } boolean provisionableCaps = true; for (SystemComponent sysReq : unsupportedReqs) { if (sysReq.getStagedSoftware()==null) { provisionableCaps = false; break; } } if (!provisionableCaps) { String failureReason = getName() + " does not meet requirements for " + provType + " service " + "[" + LoggingUtil.getLoggingName(sElem) + "] " + unsupportedReqsString; provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } long requiredSize = 0; IOException failed = null; try { for (SystemComponent sysReq : unsupportedReqs) { StagedSoftware download = sysReq.getStagedSoftware(); if (download != null) { long size = download.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for {}, received {}, abort provision request", download.getLocation(), size); requiredSize = size; break; } requiredSize += size; if (download.getPostInstallAttributes() != null && download.getPostInstallAttributes().getStagedData() != null) { StagedData postInstall = download.getPostInstallAttributes().getStagedData(); size = postInstall.getDownloadSize(); if (size < 0) { logger.warn("Unable to obtain download size for PostInstall {}, abort provision request", postInstall.getLocation()); requiredSize = size; break; } requiredSize += size; } } } } catch(IOException e) { failed = e; } if (requiredSize < 0 || failed != null) throw new ProvisionException("Service ["+LoggingUtil.getLoggingName(sElem)+"] "+ "instantiation failed", failed == null? new IOException("Unable to obtain download size"):failed, true); if (supportsStorageRequirement(requiredSize, resourceCapability.getPlatformCapabilities())) { logger.debug("{} supports provisioning requirements for {} service [{}]", getName(), provType, LoggingUtil.getLoggingName(sElem)); sElem.setProvisionablePlatformCapabilities(unsupportedReqs); return true; } double avail = getAvailableStorage(resourceCapability.getPlatformCapabilities()); StringBuilder sb = new StringBuilder(); sb.append(getName()).append(" "); if (avail>0) { double GB = Math.pow(1024, 3); avail = avail/GB; sb.append("does not have adequate disk-space for ") .append("[") .append(LoggingUtil.getLoggingName(sElem)).append("] ") .append("Required=") .append(+requiredSize).append(", ") .append("Available=").append(avail).append(" GB"); } else { sb.append("does not report a StorageCapability. ") .append("Rio cannot allocate the ") .append("[") .append(LoggingUtil.getLoggingName(sElem)) .append("] ") .append("service with a software download size of ") .append(+requiredSize).append(". ") .append("This may be due to a known limitation ") .append("found when running the ").append(getName()) .append(" on a Windows machine, or if the ") .append("DiskSpace monitor has been disabled. ") .append("Check the Cybernode environment and ") .append("configuration."); } String failureReason = sb.toString(); provisionRequest.addFailureReason(failureReason); logger.warn(failureReason); return false; } } else { String failureReason = String.format("%s does not meet general or quantitative requirements for %s service [%s]", getName(), provType, LoggingUtil.getLoggingName(sElem)); logger.debug(failureReason); return false; } } InstantiatorResource(MarshalledObject<ServiceBeanInstantiator> wrappedServiceBeanInstantiator,
                                ServiceBeanInstantiator instantiator,
                                String instantiatorName,
                                Uuid instantiatorUuid,
                                MarshalledObject<?> handback,
                                ResourceCapability resourceCapability,
                                int serviceLimit); void addDeployedService(DeployedService newDeployedService); String getName(); Uuid getInstantiatorUuid(); int getServiceElementCount(ServiceElement sElem); int getServiceElementCount(); ServiceBeanInstantiator getInstantiator(); int getServiceCount(); MarshalledObject<?> getHandback(); ResourceCapability getResourceCapability(); int getServiceLimit(); void incrementProvisionCounter(ServiceElement sElem); synchronized void decrementProvisionCounter(ServiceElement sElem); int getInProcessCounter(); int getInProcessCounter(ServiceElement sElem); String getHostAddress(); void addUninstantiable(ServiceElement serviceElement); boolean isUninstantiable(ServiceElement serviceElement); void removeUninstantiable(ServiceElement serviceElement); void setDynamicEnabledOn(); boolean getDynamicEnabled(); boolean canProvision(final ProvisionRequest provisionRequest); @Override boolean equals(Object o); @Override int hashCode();  }