Exemplo n.º 1
0
 public static ContainerConfig loadContainerConfiguration()
     throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException,
         KeyStoreException, CertificateException, SecurityException, SignatureException,
         IOException {
   ValidityTools.checkAccessibilityOfFiles(
       Main.DEFAULT_GSN_LOG4J_PROPERTIES,
       WrappersUtil.DEFAULT_WRAPPER_PROPERTIES_FILE,
       Main.DEFAULT_GSN_CONF_FILE);
   ValidityTools.checkAccessibilityOfDirs(Main.DEFAULT_VIRTUAL_SENSOR_DIRECTORY);
   PropertyConfigurator.configure(Main.DEFAULT_GSN_LOG4J_PROPERTIES);
   ContainerConfig toReturn = null;
   try {
     toReturn = loadContainerConfig(DEFAULT_GSN_CONF_FILE);
     wrappers = WrappersUtil.loadWrappers(new HashMap<String, Class<?>>());
     if (logger.isInfoEnabled())
       logger.info(
           new StringBuilder()
               .append("Loading wrappers.properties at : ")
               .append(WrappersUtil.DEFAULT_WRAPPER_PROPERTIES_FILE)
               .toString());
     if (logger.isInfoEnabled()) logger.info("Wrappers initialization ...");
   } catch (JiBXException e) {
     logger.error(e.getMessage());
     logger.error(
         new StringBuilder()
             .append("Can't parse the GSN configuration file : conf/gsn.xml")
             .toString());
     logger.error(
         "Please check the syntax of the file to be sure it is compatible with the requirements.");
     logger.error("You can find a sample configuration file from the GSN release.");
     if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e);
     System.exit(1);
   } catch (FileNotFoundException e) {
     logger.error(
         new StringBuilder()
             .append("The the configuration file : conf/gsn.xml")
             .append(" doesn't exist.")
             .toString());
     logger.error(e.getMessage());
     logger.error("Check the path of the configuration file and try again.");
     if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e);
     System.exit(1);
   } catch (ClassNotFoundException e) {
     logger.error(
         "The file wrapper.properties refers to one or more classes which don't exist in the classpath");
     logger.error(e.getMessage(), e);
     System.exit(1);
   } catch (Exception ex) {
     logger.error(ex.getMessage(), ex);
   } finally {
     return toReturn;
   }
 }
Exemplo n.º 2
0
  public void run() {
    logger.info("Started GSN Controller on port " + gsnControllerPort);
    while (true) {
      try {
        Socket socket = mySocket.accept();
        logger.debug("Opened connection on control socket.");
        socket.setSoTimeout(GSN_CONTROL_READ_TIMEOUT);

        // Only connections from localhost are allowed
        if (ValidityTools.isLocalhost(socket.getInetAddress().getHostAddress()) == false) {
          try {
            logger.warn(
                "Connection request from IP address >"
                    + socket.getInetAddress().getHostAddress()
                    + "< was denied.");
            socket.close();
          } catch (IOException ioe) {
            // do nothing
          }
          continue;
        }
        new StopManager().start();
      } catch (SocketTimeoutException e) {
        logger.debug("Connection timed out. Message was: " + e.getMessage());
      } catch (IOException e) {
        logger.warn("Error while accepting control connection: " + e.getMessage());
      }
    }
  }
Exemplo n.º 3
0
  private Main() throws Exception {

    ValidityTools.checkAccessibilityOfFiles(
        DEFAULT_GSN_LOG4J_PROPERTIES,
        WrappersUtil.DEFAULT_WRAPPER_PROPERTIES_FILE,
        DEFAULT_GSN_CONF_FILE);
    ValidityTools.checkAccessibilityOfDirs(DEFAULT_VIRTUAL_SENSOR_DIRECTORY);
    PropertyConfigurator.configure(Main.DEFAULT_GSN_LOG4J_PROPERTIES);
    //  initializeConfiguration();
    try {
      controlSocket = new GSNController(null, gsnControllerPort);
      containerConfig = loadContainerConfiguration();
      updateSplashIfNeeded(
          new String[] {
            "GSN is starting at port:" + containerConfig.getContainerPort(),
            "All GSN logs are available at: logs/gsn.log"
          });
      System.out.println(
          "Global Sensor Networks (GSN) is Starting on port "
              + containerConfig.getContainerPort()
              + "...");
      System.out.println("The logs of GSN server are available in logs/gsn.log file.");
      System.out.println("To Stop GSN execute the gsn-stop script.");
    } catch (FileNotFoundException e) {
      logger.error(
          new StringBuilder()
              .append("The the configuration file : conf/gsn.xml")
              .append(" doesn't exist.")
              .toString());
      logger.error(e.getMessage());
      logger.error("Check the path of the configuration file and try again.");
      if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e);
      throw new Exception(e);
    }
    int maxDBConnections =
        System.getProperty("maxDBConnections") == null
            ? DEFAULT_MAX_DB_CONNECTIONS
            : Integer.parseInt(System.getProperty("maxDBConnections"));
    int maxSlidingDBConnections =
        System.getProperty("maxSlidingDBConnections") == null
            ? DEFAULT_MAX_DB_CONNECTIONS
            : Integer.parseInt(System.getProperty("maxSlidingDBConnections"));
    int maxServlets =
        System.getProperty("maxServlets") == null
            ? DEFAULT_JETTY_SERVLETS
            : Integer.parseInt(System.getProperty("maxServlets"));

    // Init the AC db connection.
    if (Main.getContainerConfig().isAcEnabled() == true) {
      ConnectToDB.init(
          containerConfig.getStorage().getJdbcDriver(),
          containerConfig.getStorage().getJdbcUsername(),
          containerConfig.getStorage().getJdbcPassword(),
          containerConfig.getStorage().getJdbcURL());
    }

    mainStorage =
        StorageManagerFactory.getInstance(
            containerConfig.getStorage().getJdbcDriver(),
            containerConfig.getStorage().getJdbcUsername(),
            containerConfig.getStorage().getJdbcPassword(),
            containerConfig.getStorage().getJdbcURL(),
            maxDBConnections);
    //
    StorageConfig sc =
        containerConfig.getSliding() != null
            ? containerConfig.getSliding().getStorage()
            : containerConfig.getStorage();
    windowStorage =
        StorageManagerFactory.getInstance(
            sc.getJdbcDriver(),
            sc.getJdbcUsername(),
            sc.getJdbcPassword(),
            sc.getJdbcURL(),
            maxSlidingDBConnections);
    //
    validationStorage =
        StorageManagerFactory.getInstance(
            "org.h2.Driver", "sa", "", "jdbc:h2:mem:validator", Main.DEFAULT_MAX_DB_CONNECTIONS);

    if (logger.isInfoEnabled())
      logger.info("The Container Configuration file loaded successfully.");

    try {
      logger.debug(
          "Starting the http-server @ port: "
              + containerConfig.getContainerPort()
              + " (maxDBConnections: "
              + maxDBConnections
              + ", maxSlidingDBConnections: "
              + maxSlidingDBConnections
              + ", maxServlets:"
              + maxServlets
              + ")"
              + " ...");
      Server jettyServer =
          getJettyServer(
              getContainerConfig().getContainerPort(),
              getContainerConfig().getSSLPort(),
              maxServlets);
      jettyServer.start();
      logger.debug("http-server running @ port: " + containerConfig.getContainerPort());
    } catch (Exception e) {
      throw new Exception(
          "Start of the HTTP server failed. The HTTP protocol is used in most of the communications: "
              + e.getMessage(),
          e);
    }
    VSensorLoader vsloader = VSensorLoader.getInstance(DEFAULT_VIRTUAL_SENSOR_DIRECTORY);
    controlSocket.setLoader(vsloader);

    String msrIntegration = "gsn.msr.sensormap.SensorMapIntegration";
    try {
      vsloader.addVSensorStateChangeListener(
          (VSensorStateChangeListener) Class.forName(msrIntegration).newInstance());
    } catch (Exception e) {
      logger.warn("MSR Sensor Map integration is disabled.");
    }

    vsloader.addVSensorStateChangeListener(new SQLValidatorIntegration(SQLValidator.getInstance()));
    vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(LocalDeliveryWrapper.class));
    vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(PushDelivery.class));
    vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(RestDelivery.class));

    ContainerImpl.getInstance()
        .addVSensorDataListener(DataDistributer.getInstance(LocalDeliveryWrapper.class));
    ContainerImpl.getInstance()
        .addVSensorDataListener(DataDistributer.getInstance(PushDelivery.class));
    ContainerImpl.getInstance()
        .addVSensorDataListener(DataDistributer.getInstance(RestDelivery.class));
    vsloader.startLoading();
  }