Package org.rioproject.opstring

Examples of org.rioproject.opstring.ServiceElement


*/
public class ServiceChannelTest {
    @Test
    public void testSubscribe() {
        ServiceChannel serviceChannel = ServiceChannel.getInstance();
        ServiceElement serviceElement = TestUtil.makeServiceElement("bar", "foo");
        Listener l1 = new Listener();
        serviceChannel.subscribe(l1, serviceElement, ServiceChannelEvent.Type.PROVISIONED);
        Listener l2 = new Listener();
        serviceChannel.subscribe(l2, serviceElement, ServiceChannelEvent.Type.FAILED);
        Listener l3 = new Listener();
View Full Code Here


* @author Dennis Reedy
*/
public class IdleServiceManagerTest {
    @Test
    public void testIdleServiceManager() throws InterruptedException {
        ServiceElement serviceElement = TestUtil.makeServiceElement("bar", "foo", 2);
        IdleServiceManager idleServiceManager = new IdleServiceManager(3000l, serviceElement);
        TestServiceActivityProvider sap1 = new TestServiceActivityProvider();
        TestServiceActivityProvider sap2 = new TestServiceActivityProvider();
        idleServiceManager.addService(sap1);
        Listener l = new Listener();
View Full Code Here

     * Add a DeployedService instance to the serviceElementMap.
     *
     * @param newDeployedService The service to add
     */
    public void addDeployedService(DeployedService newDeployedService) {
        ServiceElement sElem = newDeployedService.getServiceElement();
        synchronized(serviceElementMap) {
            if(serviceElementMap.containsKey(sElem)) {
                List<DeployedService> list = serviceElementMap.get(sElem);
                if(!list.contains(newDeployedService)) {
                    list.add(newDeployedService);
View Full Code Here

    void setDeployedServices(List<DeployedService> deployedServices) {
        synchronized(serviceElementMap) {
            serviceElementMap.clear();
            for(DeployedService deployedService : deployedServices) {

                ServiceElement sElem = deployedService.getServiceElement();
                if (serviceElementMap.containsKey(sElem)) {
                    List<DeployedService> list = serviceElementMap.get(sElem);
                    if(!list.contains(deployedService)) {
                        list.add(deployedService);
                        serviceElementMap.put(sElem, list);
View Full Code Here

     * @throws ProvisionException If there are errors obtaining available disk space. Note this will only
     * happen if the {@code ProvisionRequest} contains downloadable {@code PlatformCapability} components and there
     * is a problem obtaining the size of the download.
     */
    public boolean canProvision(final ProvisionRequest provisionRequest) throws ProvisionException {
        ServiceElement sElem = provisionRequest.getServiceElement();
        if(sElem.getPlanned()==0)
            return(false);

        String provType = sElem.getProvisionType().toString();
        /*
         * Check if the serviceLimit has been reached
         */
        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);
        }

        /*
         * Check if the maximum amount per machine has been reached
         */
        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);
            }
        }

        /*
         * Fixed service allocation is similar to maxPerMachine, ensure that
         * there are not too many service allocated
         */
        if(sElem.getProvisionType() == ServiceElement.ProvisionType.FIXED) {
            int planned = sElem.getPlanned();
            int actual = getServiceElementCount(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 {
                /* Create a String representation of the unsupportedReqs
                 * object for logging */
                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));
                /* Determine if the resource supports persistent provisioning */
                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);
                }
                /*
                 * Check if the unsupported PlatformCapability objects can be
                 * provisioned. If there are any that cannot be provisioned move
                 * onto the next resource
                 */
                boolean provisionableCaps = true;
                for (SystemComponent sysReq : unsupportedReqs) {
                    if (sysReq.getStagedSoftware()==null) {
                        provisionableCaps = false;
                        break;
                    }
                }
                if(!provisionableCaps) {
                    StringBuilder message = new StringBuilder();
                    message.append(getName()).append(" does not meet requirements for ");
                    message.append(provType).append(" service ");
                    message.append("[").append(LoggingUtil.getLoggingName(sElem)).append("] ");
                    message.append("PlatformCapability objects are not configured to be downloadable: ");
                    message.append(unsupportedReqsString);
                    String failureReason = message.toString();
                    provisionRequest.addFailureReason(failureReason);
                    logger.warn(failureReason);
                    return (false);
                }
                /* Get the size of the download(s) */
                int requiredSize = 0;
                IOException failed = null;
                try {
                    for (SystemComponent sysReq : unsupportedReqs) {
                        StagedSoftware download = sysReq.getStagedSoftware();
                        if(download!=null) {
                            int size = download.getDownloadSize();
                            if(size < 0) {
                                logger.warn("Unable to obtain download size for {}, abort provision request",
                                            download.getLocation());
                                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);
                /* Find out if the resource has the necessary disk-space */
                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(" ");
View Full Code Here

         * If we have a cluster defined, then see if the provided resource has
         * either an IP address or hostname thats in the list of IP addresses
         * and hostnames in our machine cluster list. If it isnt in the list,
         * then there is no sense in proceeding
         */
        ServiceElement sElem = provisionRequest.getServiceElement();
        String[] machineCluster = sElem.getCluster();
        if(machineCluster != null && machineCluster.length > 0) {
            logger.debug("ServiceBean [{}] has a cluster requirement", LoggingUtil.getLoggingName(sElem));
            boolean found = false;
            for (String aMachineCluster : machineCluster) {
                if (aMachineCluster.equals(resourceCapability.getAddress()) ||
View Full Code Here

     * ResourceCapability does not support. If the Collection has zero entries,
     * then the provided ResourceCapability supports the Qualitative
     * Requirements specified by the ServiceBean
     */
    Collection<SystemComponent> meetsQualitativeRequirements(final ProvisionRequest request) {
        ServiceElement sElem = request.getServiceElement();
        ServiceLevelAgreements sla = sElem.getServiceLevelAgreements();
        SystemComponent[] serviceRequirements = sla.getSystemRequirements().getSystemComponents();
        List<SystemComponent> unsupportedRequirements = new ArrayList<SystemComponent>();
        /*
         * If there are no PlatformCapability requirements we can return
         * successfully
 
View Full Code Here

     * @param provisionRequest The ProvisionRequest
     * @return Return true if the provided ResourceCapability meets
     * Quantitative requirements
     */
    boolean meetsQuantitativeRequirements(final ProvisionRequest provisionRequest) {
        ServiceElement sElem = provisionRequest.getServiceElement();
        ServiceLevelAgreements sla = sElem.getServiceLevelAgreements();
        boolean provisionable = true;
        String[] systemThresholdIDs = sla.getSystemRequirements().getSystemThresholdIDs();
        if(systemThresholdIDs.length == 0)
            return (true);
        MeasuredResource[] measured = resourceCapability.getMeasuredResources();
View Full Code Here

        statements.clear();
        serviceStatementManager = new TransientServiceStatementManager(EmptyConfiguration.INSTANCE);

        for (String name : names) {
            Uuid uuid = UuidFactory.generate();
            ServiceElement element = makeServiceElement(name);
            ServiceRecord serviceRecord = new ServiceRecord(uuid, element, "hostname");
            ServiceStatement statement = new ServiceStatement(element);
            statement.putServiceRecord(recordingUuid, serviceRecord);
            statements.add(statement);
        }
View Full Code Here

        Assert.assertEquals(names.length, list.size());
    }

    @Test
    public void testGetServiceStatementsAfterSettingInactiveThenActive() throws Exception {
        ServiceElement element = makeServiceElement("Buckwheat");
        Assert.assertNotNull(element);
        ServiceStatement statement = serviceStatementManager.get(element);
        Assert.assertNotNull(statement);
        ServiceRecord[] records = statement.getServiceRecords();
        Assert.assertEquals(1, records.length);
View Full Code Here

TOP

Related Classes of org.rioproject.opstring.ServiceElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.