private void diagnostic() {
   StringBuilder infixStr = new StringBuilder();
   for (String elem : infixArray) {
     infixStr.append(elem).append(" , ");
   }
   Log.error("EmptyStack Exception for " + expression);
   Log.error(" => infix: " + infixStr.toString());
   Log.error(" => postfix: " + postfix);
 }
 private static boolean populate(Step step, NodeType nodeInstance, KevoreeDeployPhase phase) {
   for (AdaptationPrimitive adapt : step.getAdaptations()) {
     PrimitiveCommand cmd = nodeInstance.getPrimitive(adapt);
     if (cmd != null) {
       Log.trace("Populate primitive command = {}", cmd);
       phase.populate(cmd);
     } else {
       Log.warn("Unable to find a primitive command for primitive adaptation {}", adapt);
       return false;
     }
   }
   return true;
 }
Пример #3
0
  private void createOutputClient(final String id) {
    Log.debug("createOutputClient : " + id);
    this.clients.put(
        id,
        new WSMsgBrokerClient(id, host, port, path, true) {
          @Override
          public void onUnregistered(String s) {
            Log.debug("{} unregistered from remote server", id);
          }

          @Override
          public void onRegistered(String s) {
            Log.debug("{} registered on remote server", id);
          }

          @Override
          public void onMessage(Object o, final Response response) {}

          @Override
          public void onClose(int code, String reason) {
            Log.debug("Connection closed by remote server for {}", id);
          }

          @Override
          public void onError(Exception e) {}
        });
  }
Пример #4
0
  @Start
  public void start() {
    Log.debug("Start WSChan");
    clients = new HashMap<>();
    if (path == null) {
      path = "";
    }

    ContainerRoot model = modelService.getPendingModel();
    if (model == null) {
      model = modelService.getCurrentModel().getModel();
    }
    Channel thisChan = (Channel) model.findByPath(context.getPath());
    Set<String> inputPaths = Helper.getProvidedPortsPath(thisChan, context.getNodeName());
    Set<String> outputPaths = Helper.getRequiredPortsPath(thisChan, context.getNodeName());

    for (String path : inputPaths) {
      // create input WSMsgBroker clients
      createInputClient(path + "_" + context.getInstanceName());
    }

    for (String path : outputPaths) {
      // create output WSMsgBroker clients
      createOutputClient(path + "_" + context.getInstanceName());
    }
  }
Пример #5
0
 private void buildCache() {
   StringBuilder slideListBuilder = new StringBuilder();
   StringBuilder menuBuilder = new StringBuilder();
   boolean isFirst = true;
   for (String componentName : slidesList.keySet()) {
     menuBuilder
         .append("<li><a onclick=\"document.querySelector('#presentation').innerHTML = '")
         .append(componentName);
     if (!"".equals(slidesList.get(componentName)[1])) {
       menuBuilder
           .append(" - <a href=\\'")
           .append(slidesList.get(componentName)[1])
           .append("\\'>Read the paper</a>");
     }
     menuBuilder
         .append("'; ks.sendEvent(null, {'type':'RELOAD', 'url':'")
         .append(slidesList.get(componentName)[0])
         .append("'});\">")
         .append(componentName)
         .append("</a></li>\n");
     if (isFirst) {
       isFirst = false;
       slideListBuilder
           .append("jQuery(document).ready(function ($) {\n")
           .append("document.querySelector('#presentation').innerHTML = '")
           .append(componentName)
           .append("';\n\t\t") /*.append("\t\tks.sendEvent(null, {'type':'RELOAD', 'url':'")
                       .append(slidesList.get(componentName)[0]).append("'});")*/
           .append("\n});");
       if (variables.get("embedder") != null) {
         variables.put(
             "embedder",
             variables.get("embedder").replace("{slideurl}", slidesList.get(componentName)[0]));
       }
     }
   }
   org.kevoree.log.Log.debug("menu = {}", menuBuilder.toString());
   org.kevoree.log.Log.debug("slides = {}", slideListBuilder.toString());
   variables.put("menu", menuBuilder.toString());
   variables.put("initSlides", slideListBuilder.toString());
 }
Пример #6
0
  @Start
  public void start() {
    queue = new LinkedBlockingQueue<>(100000);
    BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<>(1000);

    // Declare the host you want to connect to, the endpoint, and authentication (basic auth or
    // oauth)
    Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
    StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();

    // set up some track terms
    if (trackTerms != null && !trackTerms.isEmpty()) {
      hosebirdEndpoint.trackTerms(Lists.newArrayList(trackTerms.split(" ")));
    }
    // set up some followings
    if (followingIDs != null && !followingIDs.isEmpty()) {
      Set<Long> followings = new HashSet<>();
      for (String id : followingIDs.split(" ")) {
        followings.add(Long.parseLong(id));
      }
      hosebirdEndpoint.followings(Lists.newArrayList(followings));
    }

    // These secrets should be read from a config file
    Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret);

    ClientBuilder builder =
        new ClientBuilder()
            .name("twitter-client")
            .hosts(hosebirdHosts)
            .authentication(hosebirdAuth)
            .endpoint(hosebirdEndpoint)
            .processor(new StringDelimitedProcessor(queue))
            .eventMessageQueue(eventQueue);

    client = builder.build();
    // Attempts to establish a connection.
    client.connect();

    executor.submit(
        () -> {
          while (client != null && !client.isDone()) {
            try {
              String msg = queue.poll(5000, TimeUnit.MILLISECONDS);
              if (msg != null) {
                out.send(msg, null);
              }
            } catch (InterruptedException e) {
              Log.warn("Twitter messages blocking queue interrupted while waiting.");
            }
          }
        });
  }
Пример #7
0
 @Stop
 public void stop() {
   Log.debug("Stop WSChan");
   if (this.clients != null) {
     clients
         .values()
         .stream()
         .filter(client -> client != null)
         .forEach(fr.braindead.wsmsgbroker.WSMsgBrokerClient::close);
     this.clients = null;
   }
 }
 @Stop
 public void stopSystemComponent() throws Exception {
   Log.debug(
       "Stopping system component with command: {}",
       this.getDictionary().get("STOP_COMMAND").toString());
   Process p = Runtime.getRuntime().exec(this.getDictionary().get("STOP_COMMAND").toString());
   new Thread(new ProcessStreamFileLogger(p.getInputStream())).start();
   new Thread(new ProcessStreamFileLogger(p.getErrorStream())).start();
   if (p.waitFor() != 0) {
     throw new Exception(
         "Unable to execute command: " + this.getDictionary().get("STOP_COMMAND").toString());
   }
 }
Пример #9
0
 private void apply(KevScriptEngine kengine, int tries) {
   if (tries < 5) {
     try {
       mainSite.getModelService().unregisterModelListener(this);
       kengine.atomicInterpretDeploy();
       mainSite.getModelService().registerModelListener(this);
       buildCache();
       String pattern = mainSite.getDictionary().get("urlpattern").toString();
       if (pattern.endsWith("**")) {
         pattern = pattern.replace("**", "");
       }
       if (!pattern.endsWith("/")) {
         pattern = pattern + "/";
       }
       mainSite.invalidateCacheResponse(pattern + "talks");
     } catch (Exception ignored) {
       org.kevoree.log.Log.debug("Unable to define talks.", ignored);
     }
   } else {
     org.kevoree.log.Log.warn("Unable to define talks (see debug logs for more info");
   }
 }
Пример #10
0
  private void createInputClient(final String id) {
    Log.debug("createInputClient : " + id);
    this.clients.put(
        id,
        new WSMsgBrokerClient(id, host, port, path, true) {
          @Override
          public void onUnregistered(String s) {
            Log.info("{} unregistered from remote server", id);
          }

          @Override
          public void onRegistered(String s) {
            Log.info("{} registered on remote server", id);
          }

          @Override
          public void onMessage(Object o, final Response response) {
            Callback cb = null;

            if (response != null) {
              cb =
                  new Callback() {
                    @Override
                    public void onSuccess(CallbackResult o) {
                      if (o != null) {
                        response.send(o);
                      }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                      response.send(throwable);
                    }
                  };
            }

            List<Port> ports = channelContext.getLocalPorts();
            for (Port p : ports) {
              p.send(o.toString(), cb);
            }
          }

          @Override
          public void onClose(int code, String reason) {
            Log.error("Connection closed by remote server for {}", id);
          }

          @Override
          public void onError(Exception e) {}
        });
  }
Пример #11
0
 private String findChannel(
     ContainerRoot model, String componentName, String portName, String nodeName) {
   for (MBinding mbinding : model.getMBindings()) {
     if (mbinding.getPort().getPortTypeRef().getName().equals(portName)
         && ((ComponentInstance) mbinding.getPort().eContainer()).getName().equals(componentName)
         && ((ContainerNode) mbinding.getPort().eContainer().eContainer())
             .getName()
             .equals(nodeName)) {
       org.kevoree.log.Log.debug(mbinding.getHub().getName());
       return mbinding.getHub().getName();
     }
   }
   return null;
 }
Пример #12
0
  @Start
  public void start() {
    Log.info(greetMessage);

    scheduledThreadPool.scheduleAtFixedRate(
        new Runnable() {
          @Override
          public void run() {
            hello.send(greetMessage, null);
          }
        },
        0,
        5,
        TimeUnit.SECONDS);
  }
Пример #13
0
  public void startServer() throws IOException {
    ConfigurationParser confParser = new ConfigurationParser();
    try {
      String configPath = System.getProperty("moquette.path", null);
      confParser.parse(new File(configPath, "config/moquette.conf"));
    } catch (ParseException pex) {
      Log.warn("An error occured in parsing configuration, fallback on default configuration", pex);
    }
    Properties configProps = confParser.getProperties();

    messaging = SimpleMessaging.getInstance();
    messaging.init(configProps);

    m_acceptor = new NettyAcceptor();
    m_acceptor.initialize(messaging, configProps);
  }
 @Override
 public void modelUpdated() {
   if (bootstrapping) {
     if (!KloudModelHelper.isPaaSModel(getModelService().getLastModel())) {
       try {
         ContainerRoot model = getPortByName("slave", PaaSSlaveService.class).getModel();
         if (KloudModelHelper.isPaaSModel(model)) {
           getModelService().atomicUpdateModel(model);
         }
         bootstrapping = false;
       } catch (SubmissionException e) {
         Log.warn("The request to get the PaaS model from the master fails", e);
       }
     }
   }
 }
 private static boolean executeStep(
     KevoreeCoreBean core,
     ContainerNode rootNode,
     Step step,
     NodeType nodeInstance,
     KevoreeDeployPhase phase,
     PrimitiveExecute preRollBack) {
   if (step == null) {
     return true;
   } else {
     if (core.isAnyTelemetryListener()) {
       core.broadcastTelemetry(
           TelemetryEvent.Type.DEPLOYMENT_STEP, step.getAdaptationType().name(), null);
     }
     boolean populateResult = PrimitiveCommandExecutionHelper.populate(step, nodeInstance, phase);
     if (populateResult) {
       boolean phaseResult = phase.execute();
       if (phaseResult) {
         Step nextStep = step.getNextStep();
         boolean subResult;
         if (nextStep != null) {
           KevoreeDeployPhase nextPhase = new KevoreeSeqDeployPhase(core);
           phase.successor = nextPhase;
           subResult = executeStep(core, rootNode, nextStep, nodeInstance, nextPhase, preRollBack);
         } else {
           subResult = true;
         }
         if (!subResult) {
           preRollBack.exec();
           phase.rollback();
           return false;
         } else {
           return true;
         }
       } else {
         preRollBack.exec();
         phase.rollback();
         return false;
       }
     } else {
       Log.error("Adaptation primitives must all be mapped by a primitive command");
       return false;
     }
   }
 }
Пример #16
0
 private String[] getWebServerName(ContainerRoot model) {
   for (ContainerNode node : model.getNodes()) {
     for (ComponentInstance component : node.getComponents()) {
       //				for (TypeDefinition typeDefinition :
       // component.getTypeDefinition().getSuperTypesForJ()) {
       org.kevoree.log.Log.debug(component.getTypeDefinition().getName());
       if ("SprayWebServer"
           .equals(
               component
                   .getTypeDefinition()
                   .getName())) { // must be change if the webserver implementation is changed
         return new String[] {component.getName(), node.getName()};
       }
       //				}
     }
   }
   return null;
 }
    public void run() {
      BufferedReader readerIn = null;
      try {
        readerIn = new BufferedReader(new InputStreamReader(inputStream));
        String lineIn = readerIn.readLine();
        while (lineIn != null) {
          Log.trace(lineIn);

          lineIn = readerIn.readLine();
        }
      } catch (IOException ignored) {
      } finally {
        if (readerIn != null) {
          try {
            readerIn.close();
          } catch (IOException ignored) {
          }
        }
      }
    }
Пример #18
0
 @Stop
 public void stop() {
   Log.info("Bye, world!");
   scheduledThreadPool.shutdown();
 }
Пример #19
0
 @Update
 public void update() {
   Log.info("Update: {}", greetMessage);
 }