Package org.rioproject.monitor.service

Examples of org.rioproject.monitor.service.InstantiatorResource


    int doProvision(ProvisionRequest request,
                    ServiceResource serviceResource) {
        long start = System.currentTimeMillis();
        int result = 0;
        InstantiatorResource ir = (InstantiatorResource) serviceResource.getResource();
        try {
            //ir.incrementProvisionCounter(request.getServiceElement());
            try {
                ServiceProvisionEvent event = new ServiceProvisionEvent(context.getEventSource(),
                                                                        request.getOpStringManager(),
                                                                        request.getServiceElement());
                event.setSequenceNumber(context.getServiceProvisionEventSequenceNumber().incrementAndGet());
                event.setHandback(ir.getHandback());
                /*
                * Put the instantiate invocation in a for loop, the
                * Cybernode may return null if there is a race-condition
                * where a service is terminated, the FDH notifies the
                * ServiceElementManager of the failure, the
                * ProvisionRequest is dispatched (we get to this point),
                * and the Cybernode is in the process of doing
                * housekeeping related to service termination. If we get
                * a null returned, wait the specified time and retry
                */
                int numProvisionRetries = 3;
                for (int i = 0; i < numProvisionRetries; i++) {
                    if (logger.isDebugEnabled()) {
                        String retry = (i == 0 ? "" : ", retry (" + i + ") ");
                        logger.debug("Allocating {} [{}] ...", retry, LoggingUtil.getLoggingName(request));
                    }
                    DeployedService deployedService = ir.getInstantiator().instantiate(event);
                    if (deployedService != null) {
                        jsbInstance = deployedService.getServiceBeanInstance();
                        ir.addDeployedService(deployedService);
                        logger.info("Allocated [{}]", LoggingUtil.getLoggingName(request));
                        if (logger.isTraceEnabled()) {
                            Object service = jsbInstance.getService();
                            Class serviceClass = service.getClass();
                            logger.trace("{} ServiceBeanInstance {}, Annotation {}",
                                          LoggingUtil.getLoggingName(request),
                                          jsbInstance,
                                          RMIClassLoader.getClassAnnotation(serviceClass));
                        }
                        break;
                    } else {
                        logger.debug("{} at [{}] did not allocate [{}], retry ...",
                                     ir.getName(), ir.getHostAddress(), LoggingUtil.getLoggingName(request));
                        long retryWait = 1000;
                        try {
                            Thread.sleep(retryWait);
                        } catch (InterruptedException ie) {
                            logger.trace("Interrupted while sleeping [{}] milliseconds for provision retry",
                                          retryWait);
                        }
                    }
                }

            } catch (UnknownEventException e) {
                result = ServiceProvisioner.PROVISION_FAILURE;
                failureReason = e.getLocalizedMessage();
                logger.error(failureReason);
                thrown = e;
                context.getSelector().dropServiceResource(serviceResource);
            } catch (RemoteException e) {
                result = ServiceProvisioner.PROVISION_FAILURE;
                Throwable t = ThrowableUtil.getRootCause(e);
                failureReason = t.getLocalizedMessage();
                thrown = e;
            } catch (ServiceBeanInstantiationException e) {
                if (e.isUninstantiable())
                    result = ServiceProvisioner.PROVISION_FAILURE | ServiceProvisioner.UNINSTANTIABLE_JSB;
                else
                    result = ServiceProvisioner.PROVISION_FAILURE;
                thrown = e;
                Throwable t = ThrowableUtil.getRootCause(e);
                failureReason = t.getLocalizedMessage();

            } catch (Throwable t) {
                result = ServiceProvisioner.PROVISION_FAILURE | ServiceProvisioner.UNINSTANTIABLE_JSB;
                thrown = t;
                t = ThrowableUtil.getRootCause(t);
                failureReason = t.getLocalizedMessage();
            }
        } finally {
            if (thrown != null) {
                if (!ThrowableUtil.isRetryable(thrown)) {
                    logger.warn("Drop {} {} from collection, reason: {}",
                                ir.getName(), ir.getInstantiator(), failureReason, thrown);
                    context.getSelector().dropServiceResource(serviceResource);
                    result = ServiceProvisioner.PROVISION_FAILURE | ServiceProvisioner.BAD_CYBERNODE;
                } else {
                    if (logger.isTraceEnabled())
                        logger.warn("Provisioning [{}] to [{}]",
                                   LoggingUtil.getLoggingName(request), ir.getHostAddress(), thrown);
                    else
                        logger.warn("Provisioning [{}] to [{}], {}: {}",
                                    LoggingUtil.getLoggingName(request),
                                    ir.getHostAddress(),
                                    thrown.getClass().getName(),
                                    thrown.getLocalizedMessage());
                }

            }
            ir.decrementProvisionCounter(request.getServiceElement());
            long stop = System.currentTimeMillis();
            context.getWatch().addValue(stop - start);
        }
        return (result);
    }
View Full Code Here


     * Called when resource is selected.
     *
     * @param resource The selected ServiceResource
     */
    public void serviceResourceSelected(ServiceResource resource) {
        InstantiatorResource ir = (InstantiatorResource)resource.getResource();
        synchronized(resourceList) {
            for (Bucket b : resourceList) {
                if(b.getLabel().equals(ir.getHostAddress())) {
                    List<ServiceResource> list = b.getResources();
                    for(ServiceResource s : list) {
                        InstantiatorResource i = (InstantiatorResource)s.getResource();
                        if(i.getInstantiatorUuid().equals(ir.getInstantiatorUuid())) {
                            list.set(list.indexOf(s), s);
                            break;
                        }
                    }
                    break;
View Full Code Here

    }

    @Override
    protected void add(LeasedResource resource) {
        ServiceResource sr = (ServiceResource)resource;
        InstantiatorResource ir = (InstantiatorResource)sr.getResource();
        synchronized(resourceList) {
            Bucket bucket = null;
            for(Bucket b : resourceList) {
                if(b.getLabel().equals(ir.getHostAddress())) {
                    bucket = b;
                    break;
                }
            }
            if(bucket==null) {
                bucket = new Bucket(ir.getHostAddress());
                resourceList.add(bucket);
            }

            bucket.add(sr);
            resourceList.set(resourceList.indexOf(bucket), bucket);
View Full Code Here

    }

    @Override
    protected void remove(LeasedResource resource) {
        ServiceResource sr = (ServiceResource)resource;
        InstantiatorResource ir = (InstantiatorResource)sr.getResource();
        synchronized(resourceList) {
            for(Bucket b : resourceList) {
                if(b.getLabel().equals(ir.getHostAddress())) {
                    b.remove(sr);
                    break;
                }
            }
        }
View Full Code Here

        if(logger.isTraceEnabled()) {
            StringBuilder b = new StringBuilder();
            if(resources.length>0) {
                int i=0;
                for(ServiceResource sr : resources) {
                    InstantiatorResource ir = (InstantiatorResource)sr.getResource();
                    if(i>0) {
                        b.append(", ");
                    }
                    int count = ((InstantiatorResource)sr.getResource()).getServiceCount();
                    b.append("(")
                        .append(ir.getName())
                        .append(" at ")
                        .append(ir.getHostAddress())
                        .append(", service count:")
                        .append(count)
                        .append(")");
                    i++;
                }
View Full Code Here

        if (resource == null)
            throw new IllegalArgumentException("ServiceResource is null");
        if (inProcessResource.contains(resource))
            return;
        inProcessResource.add(resource);
        InstantiatorResource ir = (InstantiatorResource) resource.getResource();
        logger.trace("{} processing {}", getType(), ir.getName());
        try {
            if(getSize() == 0)
                return;
            if(logger.isTraceEnabled()) {
                dumpCollection();
            }
            /* Now traverse the collection for everything else, skipping
             * the service elements that have been processed */
            synchronized (collection) {
                Set<Key> requests = collection.keySet();
                int numDeployed = 0;
                for (Key requestKey : requests) {
                    ProvisionRequest request = collection.get(requestKey);
                    try {
                        if (clearedMaxPerMachineAndIsolated(request, ir.getHostAddress()) && ir.canProvision(request)) {
                            numDeployed = doDeploy(resource, request);
                        }
                    } catch (ProvisionException e) {
                        request.setType(ProvisionRequest.Type.UNINSTANTIABLE);
                        logger.warn("Service [{}] is un-instantiable, do not resubmit",
                                    LoggingUtil.getLoggingName(request));
                        processProvisionFailure(request, e);
                    }

                }
            }

        } catch (Throwable t) {
            logger.warn("Processing FixedService Collection", t);
        } finally {
            inProcessResource.remove(resource);
            ir.setDynamicEnabledOn();
        }
    }
View Full Code Here

     * are already on the resource minus the number planned
     */
    private int getNumAllowed(final ServiceResource resource, final ProvisionRequest request) {
        /* Filter out isolated associations and max per machine levels set
         * at the physical level */
        InstantiatorResource ir = (InstantiatorResource) resource.getResource();
        if (!clearedMaxPerMachineAndIsolated(request, ir.getHostAddress()))
            return 0;

        int planned = request.getServiceElement().getPlanned();
        int actual = ir.getServiceElementCount(request.getServiceElement());
        int numAllowed = planned - actual;
        if (request.getServiceElement().getMaxPerMachine() != -1 &&
            request.getServiceElement().getMaxPerMachine() < numAllowed)
            numAllowed = request.getServiceElement().getMaxPerMachine();
        logger.trace("Cybernode {} has {}, can accommodate {} of {}",
                     ir.getName(), actual, numAllowed, LoggingUtil.getLoggingName(request));
        return (numAllowed);
    }
View Full Code Here

                                                            provisionRequest.getServiceElement().getName()));
            return null;
        }

        for (ServiceResource svcResource : filteredResources) {
            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 {
                logger.trace("{}, dynamic enabled: {}", ir.getName(), ir.getDynamicEnabled());
            }
        }
        return (null);
    }
View Full Code Here

        InstantiatorResource[] known = getInstantiatorResources(provisionRequest.getServiceElement(), true);
       
        List<ServiceResource> candidateList = new ArrayList<ServiceResource>();
        candidateList.addAll(Arrays.asList(candidates));
        for (ServiceResource candidate1 : candidates) {
            InstantiatorResource candidate = (InstantiatorResource) candidate1.getResource();
            if (!AssociationMatcher.meetsIsolatedRequirements(provisionRequest.getServiceElement(), candidate, known)) {
                candidateList.remove(candidate1);
            }
        }
        if(logger.isDebugEnabled() && candidateList.isEmpty()) {
View Full Code Here

         * 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) {
View Full Code Here

TOP

Related Classes of org.rioproject.monitor.service.InstantiatorResource

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.