Package org.rioproject.deploy

Examples of org.rioproject.deploy.ServiceBeanInstantiationException


            /* Get the cause if we have an InvocationTargetException, it will allow the thrown exception
             * to have a more meaningful cause. */
             if(t instanceof InvocationTargetException) {
                 t = t.getCause()==null? ((InvocationTargetException)t).getTargetException(): t.getCause();
            }
            throw new ServiceBeanInstantiationException("Service Instantiation Exception", t, true);
        }
        return created;
    }
View Full Code Here


        return activatedService;
    }

    private Object instantiateBean(ServiceElement elem) throws ServiceBeanInstantiationException {
        if(elem.forkService())
            throw new ServiceBeanInstantiationException("The StaticCybernode does not " +
                                                        "support the instantiation of a " +
                                                        "service declared to be forked");
        ServiceBeanInstance instance = instantiator.activate(elem,
                                                             null,  // OperationalStringManager
                                                             null); // EventHandler (slas)
View Full Code Here

        /* Invoke the method with @SetConfiguration annotation or the setConfiguration method */
        Configuration config ;
        try {
            config = context.getConfiguration();
        } catch (ConfigurationException e) {
            throw new ServiceBeanInstantiationException(e.getLocalizedMessage());
        }
        BeanHelper.invokeBeanMethod(bean,
                                    SetConfiguration.class,
                                    "setConfiguration",
                                    new Class[]{Configuration.class},
View Full Code Here

            /* Invoke the start method */
            proxy = adapter.start(context);
        } catch(Exception e) {
            if(e instanceof ServiceBeanInstantiationException)
                throw (ServiceBeanInstantiationException)e;
            throw new ServiceBeanInstantiationException("Service Instantiation Exception", e, true);
        }
        return (new Created(bean, proxy, adapter));
    }
View Full Code Here

            Thread.currentThread().setContextClassLoader(currentCL);
        }
        if(abort!=null) {
            String message = String.format("Invoking Bean [%s] %s() method", bean.getClass().getName(), methodNameToInvoke);
            logger.warn(message, abort);
            throw new ServiceBeanInstantiationException(message, abort, true);
        }
    }
View Full Code Here

        } finally {
            Thread.currentThread().setContextClassLoader(currentCL);
        }
        if(abort!=null) {
            String message = String.format("Invoking Bean [%s] %s() method", bean.getClass().getName(), methodNameToInvoke);
            throw new ServiceBeanInstantiationException(message, abort, true);
        }
        return (result);
    }
View Full Code Here

        } catch(ConfigurationException e) {
            logger.warn("Getting pidFileWaitTime, using default", e);
        }
        execDescriptor = context.getServiceElement().getExecDescriptor();
        if(execDescriptor==null)
            throw new ServiceBeanInstantiationException("An ExecDescriptor is required " +
                                                "by the ServiceExecutor," +
                                                " unable to proceed.");

        String cmdLine = getCommandLine(execDescriptor);
        if(!cmdLine.startsWith(File.separator)) {
            PlatformCapability[] pCaps =
                context.getComputeResourceManager().getMatchedPlatformCapabilities();
            boolean matched = false;
            for(PlatformCapability pCap : pCaps) {
                if(pCap.getPath()!=null) {
                    File toExec = new File(pCap.getPath(), cmdLine);
                    if(toExec.exists() && toExec.canRead()) {
                        matched = true;
                        if(logger.isInfoEnabled()) {
                            logger.info("Adding PlatformCapability PATH [{}] to declared command line [{}]",
                                        pCap.getPath(), cmdLine);
                        }
                       
                        execDescriptor = Util.extendCommandLine(pCap.getPath(), execDescriptor);
                        break;
                    }
                }
            }
            if(!matched) {
                throw new ServiceBeanInstantiationException(
                    "ExecDescriptor with command line " +
                    "["+execDescriptor.getCommandLine()+"] " +
                    "cannot " +
                    "be executed, no associated PlatformCapability " +
                    "found");
            }
        } else {
            if(logger.isInfoEnabled()) {
                logger.info("Using command line [{}]",  execDescriptor.getCommandLine());
            }
        }

        File toExec = new File(execDescriptor.getCommandLine());
        if(!toExec.exists())
            throw new ServiceBeanInstantiationException("The command line ["+
                                                        execDescriptor.getCommandLine()+
                                                        "] can not be found, " +
                                                        "unable to continue. Check " +
                                                        "that the directory structure " +
                                                        "matches that as found on the " +
View Full Code Here

        String[] configs = (String[])context.getConfiguration().getEntry("spring",
                                                                         "config",
                                                                         String[].class,
                                                                         new String[]{""});
        if(configs.length==0) {
            throw new ServiceBeanInstantiationException("No Spring service configuration");
        }
        String codebase = context.getServiceElement().getExportBundles()[0].getCodebase();
        for(int i=0; i<configs.length; i++) {
            if(configs[i].contains(CODEBASE_TOK + "/")) {
                configs[i] = replace(configs[i], CODEBASE_TOK+"/", codebase);
View Full Code Here

                                    final String classPath) throws Exception {
        ExecDescriptor exDesc = new ExecDescriptor();

        String rioHome = System.getProperty("RIO_HOME");
        if(rioHome==null)
            throw new ServiceBeanInstantiationException(String.format("Cannot exec service [%s], unknown RIO_HOME system property",
                                                                      sElem.getName()));
        String classPathToUse;
        if(classPath==null)
            classPathToUse = CommandLineHelper.generateRioStarterClassPath();
        else
            classPathToUse = classPath;

        /* Create a normalized service name, translating " " to "_" and
         * appending the instance ID to the name. This will be used for the
         * log name and the registry bind name */
        String normalizedServiceName = RMIServiceNameHelper.createNormalizedServiceName(sElem);
        String serviceBindName = RMIServiceNameHelper.createBindName(sElem);

        /* Get the Cybernode's RMI Registry */
        int regPort = RegistryUtil.checkRegistry();
        String sPort = Integer.toString(regPort);

        String logDir = getLogDirectory(config, sElem.getOperationalStringName());
        if(!logDir.endsWith(File.separator))
            logDir = logDir+File.separator;
        logger.info("Logging for {} will be sent to {}", sElem.getName(), logDir);

        /* Create command line */
        exDesc.setCommandLine(CommandLineHelper.getJava());

        /* Create input args */
        StringBuilder inputArgsBuilder = new StringBuilder();
        inputArgsBuilder.append(CommandLineHelper.getClassPath(classPathToUse));
        String jvmOptions = (sElem.getExecDescriptor()==null? null: sElem.getExecDescriptor().getInputArgs());
        inputArgsBuilder.append(CommandLineHelper.createInputArgs(normalizedServiceName,
                                                                  serviceBindName,
                                                                  sPort,
                                                                  jvmOptions,
                                                                  logDir));
        inputArgsBuilder.append(CommandLineHelper.getStarterClass()).append(" ");
        String serviceBeanExecStarter = CommandLineHelper.getStarterConfig(rioHome);
        logger.trace("Using service bean exec starter: {}", serviceBeanExecStarter);
        inputArgsBuilder.append(serviceBeanExecStarter);

        exDesc.setInputArgs(inputArgsBuilder.toString());
        exDesc.setWorkingDirectory(System.getProperty("user.dir"));

        /* If we have an exec descriptor, make add any environment settings the
         * service has declared */
        if(sElem.getExecDescriptor()!=null) {
            Map<String, String> env = sElem.getExecDescriptor().getEnvironment();
            for(Map.Entry<String, String> entry : env.entrySet()) {
                env.put(entry.getKey(), PropertyHelper.expandProperties(entry.getValue()));
            }
            exDesc.setEnvironment(env);
        }

        String serviceOut = logDir+normalizedServiceName+".out";
        exDesc.setStdErrFileName(serviceOut);
        exDesc.setStdOutFileName(serviceOut);

        try {
            Registry registry = LocateRegistry.getRegistry(regPort);
            ForkedServiceBeanListener forkedServiceListener = new ForkedServiceBeanListener(discardManager);
            ServiceBeanExecListener listener = forkedServiceListener.getServiceBeanExecListener();
            long start = System.currentTimeMillis();

            Shell shell = ShellFactory.createShell();
            try {
                String shellTemplate = (String)config.getEntry(COMPONENT,
                                                               "serviceBeanExecShellTemplate",
                                                               String.class,
                                                               null);
                if(shellTemplate!=null)
                    shell.setShellTemplate(shellTemplate);
            } catch (ConfigurationException e) {
                logger.warn("Cannot get shell template from configuration, continue with default");
            }
            logger.info("Invoke {}.exec for {}, working directory {}",
                        shell.getClass().getName(), ServiceLogUtil.logName(sElem), exDesc.getWorkingDirectory());
            manager = shell.exec(exDesc);
            forkedServiceListener.setName(serviceBindName);
            forkedServiceListener.setRegistryPort(regPort);

            long wait = 0;
            do {
                try {
                    execHandler = (ServiceBeanExecutor)registry.lookup(serviceBindName);
                    forkedServiceListener.createFDH(execHandler);
                    execHandler.setUuid(uuid);
                    execHandler.setServiceBeanExecListener(listener);

                    if(installedPlatformCapabilities!=null && installedPlatformCapabilities.length>0)
                        execHandler.applyPlatformCapabilities(installedPlatformCapabilities);
                    instance = execHandler.instantiate(sElem, opStringMgr);
                    long activationTime = System.currentTimeMillis()-start;
                    logger.info("Forked instance created for [{}], pid=[{}], activation time={} ms",
                                serviceBindName, manager.getPid(), activationTime);
                    break;
                } catch (NotBoundException e) {
                    try {
                        Thread.sleep(1000);
                        wait++;
                    } catch (InterruptedException e1) {
                        logger.warn("Interrupted waiting for ServiceBean [{}] to register into Registry",
                                    serviceBindName);
                    }
                }
            } while (wait < forkedServiceWaitTime);

            if (wait >= forkedServiceWaitTime) {
                logger.warn("Timed out waiting for [{}]. Waited [{}] seconds, configured wait " +
                            "time is [{}] seconds. Killing spawned process and unregistering from local " +
                            "registry. Check the service's output log to determine root cause(s)",
                            serviceBindName, wait, forkedServiceWaitTime);
                manager.destroy(true);
                throw new ServiceBeanInstantiationException("Failed to fork");
            }

        } catch (Exception e) {
            unregister(regPort, serviceBindName);
            logger.info("Terminate process for ServiceBean [{}]", serviceBindName);
View Full Code Here

            if(cause instanceof ServiceBeanInstantiationException) {
                throw (ServiceBeanInstantiationException)cause;
            } else {
                String message = String.format("ServiceBean %s instantiation failed",
                                               ServiceLogUtil.logName(context.getServiceElement()));
                throw new ServiceBeanInstantiationException(message, t, true);
            }
        }
        return (proxy);
    }
View Full Code Here

TOP

Related Classes of org.rioproject.deploy.ServiceBeanInstantiationException

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.