Package org.trpr.platform.core

Examples of org.trpr.platform.core.PlatformException


                handler.shutdown(taskContext);
                handler.init(taskContext);
                handler.activate();
            } catch (Exception e) {
                LOGGER.error("Error initializing " + this.getHandlerType().getName() + " : {}. Error is: " + e.getMessage(), handler.getName(), e);
                throw new PlatformException("Error reinitialising "  + this.getHandlerType().getName() + " : " + handler.getName(), e);
            }
        }     
    }
View Full Code Here


        try {
        initedHandler = handlerInitTask.get();       
      } catch (Exception e) {
                LOGGER.error("Error initializing handlers of type : " + getHandlerType().getName() + ".Error is: " + e.getMessage(), e);
                pool.shutdownNow();
              throw new PlatformException("Error initializing handlers of type : " + getHandlerType().getName() + ".Error is: " + e.getMessage(), e);
      }
            if (!initedHandler.isActive()) {
              if (initedHandler.getInitOutcomeStatus() == AbstractHandler.VETO_INIT) {                       
                    pool.shutdownNow();
                    throw new PlatformException("Error initializing vetoing handler " + getHandlerType().getName() + " : " + initedHandler.getName());
              } else {
                LOGGER.warn("Continuing after init failed for non-vetoing handler " + getHandlerType().getName() + " : " + initedHandler.getName());
              }
            } 
      }
    LOGGER.info("Number of handlers inited : " + handlerInitTasks.size());
      while(!pool.isTerminated()) {
        pool.shutdown();
        try {
        pool.awaitTermination(10, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        // we dont expect this to happen, but if it does, throw a Platform exception
                throw new PlatformException("Error initializing handlers. Init interrupted. Error is : " + e.getMessage(), e);
      }
      }
    }
View Full Code Here

                    LOGGER.error("Fatal error. commandName not specified in initializationCommands for TaskHandler: " + this.getName());
                    throw new UnsupportedOperationException("Fatal error. commandName not specified in initializationCommands of TaskHandler: "+this.getName());
                }
                TaskResult result = this.execute(taskContext, commandName, new HashMap<String, String>(initParam), null);
                if (result != null && !result.isSuccess()) {
                    throw new PlatformException("Initialization command: "+commandName+" failed for TaskHandler: "+this.getName()+" The params were: "+initParam);
                }
            }
        }
    }
View Full Code Here

        }
      } 
    }
    catch(Exception e) {
      LOGGER.error("Unable to get the job name from the given Spring Batch configuration file", e);
      throw new PlatformException(e);
    }
    return jobNameList;
  }
View Full Code Here

                final String errorMessage = "Found multiple common-proxy-handler-configs, only one is allowed";
                LOGGER.error(errorMessage);
                for (File commonHandlerConfig : commonProxyHandlerConfigFiles) {
                    LOGGER.error(commonHandlerConfig.getAbsolutePath());
                }
                throw new PlatformException(errorMessage);
            }
        }

        // locate and load the individual proxy handler bean XML files using the common proxy handler beans context as parent
        File[] proxyHandlerBeansFiles = FileLocator.findFiles(ServiceProxyFrameworkConstants.SPRING_PROXY_HANDLER_CONFIG);
        for (File proxyHandlerBeansFile : proxyHandlerBeansFiles) {
            HandlerConfigInfo handlerConfigInfo = new HandlerConfigInfo(proxyHandlerBeansFile);
            // load the proxy handler's appcontext
            this.loadProxyHandlerContext(handlerConfigInfo);
            LOGGER.info("Loaded: " + proxyHandlerBeansFile);
        }

        // add the proxy listener beans to the contexts list (these have the thrift handlers)
        File[] proxyListenerBeanFiles = FileLocator.findFiles(ServiceProxyFrameworkConstants.SPRING_PROXY_LISTENER_CONFIG);
        for (File proxyListenerBeanFile : proxyListenerBeanFiles) {
            // locate and load the service proxy listener defined in the file identified by {@link ServiceProxyFrameworkConstants#SPRING_PROXY_LISTENER_CONFIG}
            AbstractApplicationContext listenerContext = new FileSystemXmlApplicationContext(
                    new String[]{FILE_PREFIX + proxyListenerBeanFile.getAbsolutePath()},
                    ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext()
            );
            this.handlerConfigInfoList.add(new HandlerConfigInfo(proxyListenerBeanFile, null, listenerContext));
            LOGGER.info("Loaded: " + proxyListenerBeanFile);
        }

        // store reference to the TaskContext
        this.taskContext = (TaskContext) ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext().getBean(ServiceProxyComponentContainer.TASK_CONTEXT_BEAN);
       
        // load all registries
        for (HandlerConfigInfo handlerConfigInfo : handlerConfigInfoList) {
            // handler registries
            String[] registryBeans = handlerConfigInfo.getProxyHandlerContext().getBeanNamesForType(AbstractHandlerRegistry.class);
            for (String registryBean : registryBeans) {
                AbstractHandlerRegistry<T> registry = (AbstractHandlerRegistry<T>) handlerConfigInfo.getProxyHandlerContext().getBean(registryBean);
                LOGGER.info("Found handler registry: " + registry.getClass().getName() + " in file : " + handlerConfigInfo.getXmlConfigFile().getAbsolutePath());
                // ensure that the same registry is not added twice in any of the config files
                if (this.configService.getDeployedRegistries().contains(registry)) {
                   LOGGER.error("Error initializing registry: " + registry.getClass().getName() + ". Duplicate reference in location : " + handlerConfigInfo.getXmlConfigFile().getAbsolutePath());
                  throw new PlatformException("Error initializing registry: " + registry.getClass().getName() + ". Duplicate reference in location : " + handlerConfigInfo.getXmlConfigFile().getAbsolutePath());
                }
                // init the Registry
                try {
                    AbstractHandlerRegistry.InitedHandlerInfo<T>[] initedHandlerInfos = registry.init(this.handlerConfigInfoList, this.taskContext);
                    LOGGER.info("Initialized handler registry: " + registry.getClass().getName());
                    //Add the file path of each inited handler to SPConfigService (for configuration console)
                    for (AbstractHandlerRegistry.InitedHandlerInfo<T> initedHandlerInfo : initedHandlerInfos) {
                      if (initedHandlerInfo == null) {
                        System.out.println("Handler is nul!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + " Size is : " + initedHandlerInfos.length);
                      }
                        this.configService.addHandlerConfigPath(initedHandlerInfo.getHandlerConfigInfo().getXmlConfigFile(), initedHandlerInfo.getInitedHandler());
                    }
                } catch (Exception e) {
                    LOGGER.error("Error initializing registry: " + registry.getClass().getName());
                    throw new PlatformException("Error initializing registry: " + registry.getClass().getName(), e);
                }
                // add registry to config
                this.configService.addHandlerRegistry(registry);
                // add registry to local list
                this.registries.add(registry);
            }

            // add all network servers to config
            String[] networkServerBeans = handlerConfigInfo.getProxyHandlerContext().getBeanNamesForType(AbstractNetworkServer.class);
            for (String networkServerBean : networkServerBeans) {
                AbstractNetworkServer networkServer = (AbstractNetworkServer) handlerConfigInfo.getProxyHandlerContext().getBean(networkServerBean);
                // init the server
                try {
                    networkServer.init();
                } catch (Exception e) {
                    LOGGER.error("Error initializeing network server: " + networkServer.getServerType() + ": " + networkServer.getServerEndpoint());
                    throw new PlatformException("Error initializeing network server: " + networkServer.getServerType() + ": " + networkServer.getServerEndpoint(), e);
                }
                configService.addDeployedNetworkServer(networkServer);
            }

        }
View Full Code Here

                reloadHandlerConfigInfoList.add(handlerConfigInfo);
                try {
                    registry.init(reloadHandlerConfigInfoList, taskContext);
                } catch (Exception e) {
                    LOGGER.error("Error updating registry : " + registry.getClass().getName() + " for handler : " + handler.getName(), e);
                    throw new PlatformException("Error updating registry : " + registry.getClass().getName() + " for handler : " + handler.getName(), e);
                }
                return;
            }
        }
    }
View Full Code Here

                for (int i = 0; i < libFiles.length; i++) {
                    libURLs[i] = new URL(HandlerConfigInfo.FILE_PREFIX + libFiles[i].getAbsolutePath());
                }
                proxyHandlerCL = new URLClassLoader(libURLs, this.tccl);
            } catch (MalformedURLException e) {
                throw new PlatformException(e);
            }
        }
        // now load the proxy handler context and add it into the handlerConfigInfoList list
        handlerConfigInfo.loadProxyHandlerContext(proxyHandlerCL, ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext());
        this.handlerConfigInfoList.add(handlerConfigInfo);
View Full Code Here

      File oldHandlerFile = null;
      try {
        oldHandlerFile = this.getHandlerConfig(handlerName).getFile();
      } catch (IOException e1) {
        LOGGER.error("Handler Config File for handler: "+handlerName+" not found. Returning");
        throw new PlatformException("File not found for handler: "+handlerName,e1);
      }
      if (!oldHandlerFile.exists()) {
        LOGGER.error("Handler Config File: "+oldHandlerFile.getAbsolutePath()+" doesn't exist. Returning");
        throw new PlatformException("File not found: "+oldHandlerFile.getAbsolutePath());
      }

        // Check for read permissions
      if (!oldHandlerFile.canRead()) {
        LOGGER.error("No read permission for: "+oldHandlerFile.getAbsolutePath()+". Returning");
        throw new PlatformException("Read permissions not found for file: "+oldHandlerFile.getAbsolutePath());
      }

      // Check for write permissions
      if (!oldHandlerFile.canWrite()) {
        LOGGER.error("No write permission for: "+oldHandlerFile.getAbsolutePath()+". Write permissions are required to modify handler confib");
        throw new PlatformException("Required permissions not found for modifying file: "+oldHandlerFile.getAbsolutePath());
      }

        // create backup
      this.createPrevConfigFile(handlerName);

        // file_put_contents Java :-/
      try {
        this.upload(modifiedHandlerConfigFile.getByteArray(), oldHandlerFile.getAbsolutePath());
      } catch (IOException e) {
        LOGGER.error("IOException while uploading file to path: "+oldHandlerFile.getAbsolutePath());
        this.restorePrevConfigFile(handlerName);
        throw new PlatformException(e);
      }

      // get the registered AbstractHandler for the file name
      T handler = this.configURItoHandlerName.get(oldHandlerFile.toURI()).get(0);
        // re-load the handler
        // TODO
        // loading component destroys all beans in the config file given by the handler config info
        // this mean this only works if only one handler per handler xml file
      try {
        this.componentContainer.reloadHandler(handler, this.getHandlerConfig(handlerName));
      } catch(Exception e) {
        this.restorePrevConfigFile(handlerName);
        this.componentContainer.loadComponent(this.getHandlerConfig(handlerName));
        throw new PlatformException(e);
      }
      this.removePrevConfigFile(handlerName);
    }
View Full Code Here

    File configFile = null;
    try {
      configFile = this.getHandlerConfig(handlerName).getFile();
    } catch (IOException e1) {
      LOGGER.error("Exception while getting handlerConfigFile",e1);
      throw new PlatformException("Exception while getting handlerConfigFile",e1);
    }

        // create the backup file
    File prevFile = new File(configFile.getParent()+"/"+SPConfigServiceImpl.PREV_HANDLER_FILE);

        // move current -> backup, create new current file
    if (configFile.exists()) {
      if (prevFile.exists()) {
        prevFile.delete();
      }
      configFile.renameTo(prevFile);
      try {
        configFile.createNewFile();
      } catch (IOException e) {
        LOGGER.error("IOException while clearing config File",e);
        throw new PlatformException("IOException while clearing config File",e);
            }
      prevFile.deleteOnExit();
    }

  }
View Full Code Here

    // Creating directory structure
    try {
      destFile.getParentFile().mkdirs();
    } catch(Exception e) {
      LOGGER.error("Unable to create directory structure for uploading file");
      throw new PlatformException("Unable to create directory structure for uploading file");
    }

    FileOutputStream fos = new FileOutputStream(destFile);
    fos.write(fileContents);           
  }
View Full Code Here

TOP

Related Classes of org.trpr.platform.core.PlatformException

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.