Package org.rioproject.opstring

Examples of org.rioproject.opstring.ServiceElement


    private final Uuid recordingUuid = UuidFactory.generate();

    @Test
    public void testAddingServiceRecords() {
        List<ServiceRecord> list = new ArrayList<ServiceRecord>();
        ServiceElement element = makeServiceElement("Foo");
        int recordCount = 200;
        for(int i=0; i<recordCount; i++) {
            Uuid uuid = UuidFactory.generate();
            list.add(new ServiceRecord(uuid, element, "hostname"));
View Full Code Here


    }

    @Test
    public void testUpdatingServiceRecords() {
        List<ServiceRecord> list = new ArrayList<ServiceRecord>();
        ServiceElement element = makeServiceElement("Foo");
        int recordCount = 200;
        for(int i=0; i<recordCount; i++) {
            Uuid uuid = UuidFactory.generate();
            list.add(new ServiceRecord(uuid, element, "hostname"));
View Full Code Here

        Assert.assertFalse(statement.hasActiveServiceRecords());
    }

    @Test
    public void testGetOrganization() {
        ServiceElement element = makeServiceElement("Foo");
        Uuid uuid = UuidFactory.generate();
        ServiceRecord record = new ServiceRecord(uuid, element, "hostname");
        ServiceStatement statement = new ServiceStatement(element);
        statement.putServiceRecord(recordingUuid, record);
        String organization = statement.getOrganization();
View Full Code Here

        String organization = statement.getOrganization();
        Assert.assertNotNull(organization);
    }

    private ServiceElement makeServiceElement(String name) {
        ServiceElement elem = new ServiceElement();
        ClassBundle main = new ClassBundle("");
        elem.setComponentBundle(main);
        ServiceBeanConfig sbc = new ServiceBeanConfig();
        sbc.setName(name);
        elem.setServiceBeanConfig(sbc);
        return elem;
    }
View Full Code Here

                                                         double.class,
                                                         defaultSystemThreshold);
        sla.getSystemRequirements().addSystemThreshold(SystemRequirements.SYSTEM,
                                                       new ThresholdValues(0.0, systemThreshold));

        ServiceElement sElem = new ServiceElement(ServiceElement.ProvisionType.EXTERNAL,
                                                  sbConfig,
                                                  sla,
                                                  new ClassBundle[]{exportBundle});
        if(sbLifeCycleManager == null)
            sbLifeCycleManager = new LifeCycleManager();
View Full Code Here

            for (Key key : keys) {
                ProvisionRequest pr = collection.get(key);
                if (sElem.equals(pr.getServiceElement())) {
                    /* Preserve instance IDs */
                    Long id = pr.getServiceElement().getServiceBeanConfig().getInstanceID();
                    ServiceElement newElem = sElem;
                    if (id != null)
                        newElem = ServiceElementUtil.prepareInstanceID(sElem, id.intValue());
                    pr.setServiceElement(newElem);
                    if(listener!=null) {
                        pr.setServiceProvisionListener(listener);
View Full Code Here

            buffer.append(type);
            buffer.append(" collection size : ");
            buffer.append(elements.length).append("\n");
            buffer.append("--\n");
            for (ProvisionRequest element : elements) {
                ServiceElement sElem = element.getServiceElement();
                Long id = sElem.getServiceBeanConfig().getInstanceID();
                buffer.append(x++);
                buffer.append(" ");
                buffer.append(sElem.getOperationalStringName());
                buffer.append("/");
                buffer.append(sElem.getName());
                if(!type.startsWith("Fixed")) {
                    buffer.append(" instanceID=");
                    buffer.append(id);
                }
                buffer.append("\n");
View Full Code Here

            InstantiatorResource ir = (InstantiatorResource) svcResource.getResource();
            /*
             * Make sure the InstantiatorResource has not reached it's
             * serviceLimit
             */
            ServiceElement sElem = provisionRequest.getServiceElement();
            int serviceLimit = ir.getServiceLimit();
            int total = ir.getServiceElementCount() + ir.getInProcessCounter();
            if (total >= serviceLimit) {
                String reason =
                    String.format("%s reached service limit of [%d] (service element count:%d, in-process:%d), " +
                                  "cannot be used to instantiate [%s/%s]",
                                  ir.getName(),
                                  serviceLimit,
                                  ir.getServiceElementCount(),
                                  ir.getInProcessCounter(),
                                  sElem.getOperationalStringName(),
                                  sElem.getName());
                provisionRequest.addFailureReason(reason);
                logger.debug(reason);
                continue;
            }
            /*
             * Check if the InstantiatorResource doesn't already have the
             * maximum amount of services allocated. this is different then
             * MaxPerNode
             */
            int planned = sElem.getPlanned();
            int actual = ir.getServiceElementCount(sElem);
            logger.trace("{} has [{}] instance(s), planned [{}] of [{}/{}]",
                         ir.getName(), actual, planned, sElem.getOperationalStringName(), sElem.getName());
            if (actual >= planned) {
                String message = String.format("%s has reached service limit of [%s], cannot be used to instantiate [%s/%s]",
                                               ir.getName(), serviceLimit, sElem.getOperationalStringName(), sElem.getName());
                provisionRequest.addFailureReason(message);
                continue;
            }
            if (ir.getDynamicEnabled()) {
                try {
                    if (ir.canProvision(provisionRequest)) {
                        serviceResourceSelected(svcResource);
                        logger.trace("[{}, service count: {}] has been selected for service [{}/{}]",
                                     ir.getName(), ir.getServiceCount(), sElem.getOperationalStringName(),
                                     sElem.getName());
                        return (svcResource);
                    }
                } catch (Exception e) {
                    logger.warn("[{}] during canProvision check for [{}]",
                                ir.getName(), sElem.getOperationalStringName(), sElem.getName(),
                                e);
                    if(e instanceof ProvisionException)
                        throw (ProvisionException)e;
                }
            } else {
View Full Code Here

     * @param provisionRequest
     * @param candidates
     * @return
     */
    public ServiceResource[] filterMachineBoundaries(final ProvisionRequest provisionRequest, final ServiceResource... candidates) {
        ServiceElement elem = provisionRequest.getServiceElement();
        int maxPerMachine = elem.getMaxPerMachine();
        if(!(maxPerMachine!=-1 &&
             elem.getMachineBoundary()==ServiceElement.MachineBoundary.PHYSICAL)) {
            return(candidates);
        }

        /*
         * 1. Create a table composed of keys that are the host address and
         *    values a list of Cybernodes
         * 2. Count the number services each cybernode has on each host
         * 3. Remove table entries that exceed the count per host
         */
        Map<String, List<ServiceResource>> table = new HashMap<String, List<ServiceResource>>();

        for (ServiceResource candidate : candidates) {
            InstantiatorResource ir = (InstantiatorResource)candidate.getResource();
            List<ServiceResource> list = table.get(ir.getHostAddress());
            if(list==null)
                list = new ArrayList<ServiceResource>();
            list.add(candidate);
            table.put(ir.getHostAddress(), list);
        }

        List<String> remove = new ArrayList<String>();
        for(Map.Entry<String, List<ServiceResource>> entry : table.entrySet()) {
            List<ServiceResource> list = entry.getValue();
            int serviceCount = 0;
            for(ServiceResource sr : list) {
                InstantiatorResource ir = (InstantiatorResource)sr.getResource();
                serviceCount += ir.getInProcessCounter(elem) + ir.getServiceElementCount(elem);
                if(serviceCount>=maxPerMachine) {
                    remove.add(ir.getHostAddress());
                    break;
                }
            }
        }
        for(String s : remove) {
            table.remove(s);
        }

        List<ServiceResource> candidateList = new ArrayList<ServiceResource>();
        for(Map.Entry<String, List<ServiceResource>> entry : table.entrySet()) {
            List<ServiceResource> list = entry.getValue();
            for(int i=0; i<list.size(); i++) {
                if(i<maxPerMachine) {
                    candidateList.add(list.get(i));
                } else {
                    break;
                }
            }
        }

        if(logger.isDebugEnabled() && candidateList.isEmpty() && elem.getProvisionType().equals(ServiceElement.ProvisionType.DYNAMIC)) {
            logger.debug("Service [{}/{}] has a physical machine boundary constraint and an " +
                         "instance of the service has been found on all known machines.",
                         elem.getOperationalStringName(), elem.getName());
        }
        return(candidateList.toArray(new ServiceResource[candidateList.size()]));
    }
View Full Code Here

            String impl = "<not declared>";
            Throwable thrown;
            if(event instanceof ProvisionFailureEvent) {
                String label = "ProvisionFailureEvent."+eventNode.getValueAt(0);
                ProvisionFailureEvent pfe = (ProvisionFailureEvent)event;
                ServiceElement elem = pfe.getServiceElement();
                if(elem.getComponentBundle()!=null)
                    impl = elem.getComponentBundle().getClassName();
                thrown = pfe.getThrowable();
                String exception = getExceptionText(thrown);
                tableData.put("Event", label);
                tableData.put("When", Constants.DATE_FORMAT.format(event.getDate()));
                tableData.put("Deployment", elem.getOperationalStringName());
                tableData.put("Service", elem.getName());
                tableData.put("Class", impl);
                StringBuilder builder = new StringBuilder();
                for(String reason : pfe.getFailureReasons()) {
                    if(builder.length()>0)
                        builder.append("\n    ");
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.