Ejemplo n.º 1
0
 /**
  * A real node-function (using the node argument). Returns the next newer node of same type. Also
  * a nice example on the difference between core and bridge.
  */
 public Object successor() {
   if (node == null) throw new IllegalArgumentException("successor is a node-function");
   if (cloud != null) {
     log.debug("Using bridge (security restrictions will be honoured)");
     NodeManager nm = node.getNodeManager();
     NodeQuery q = nm.createQuery();
     StepField field = q.getStepField(nm.getField("number"));
     q.setConstraint(
         q.createConstraint(
             field, FieldCompareConstraint.GREATER, Integer.valueOf(node.getNumber())));
     q.addSortOrder(field, SortOrder.ORDER_ASCENDING);
     q.setMaxNumber(1);
     NodeIterator i = nm.getList(q).nodeIterator();
     return i.hasNext() ? i.nextNode() : null;
   } else {
     log.debug("Using core.");
     throw new UnsupportedOperationException("Core implementation was dropped. See source code.");
     /* This is how it would go with core objects
     MMObjectBuilder builder = MMBase.getMMBase().getBuilder(node.getNodeManager().getName());
     NodeSearchQuery query = new NodeSearchQuery(builder);
     StepField field = query.getField(builder.getField("number"));
     BasicFieldValueConstraint cons = new BasicFieldValueConstraint(field, node.getNumber());
     cons.setOperator(FieldCompareConstraint.GREATER);
     query.setConstraint(cons);
     query.addSortOrder(field);
     query.setMaxNumber(1);
     try {
         java.util.Iterator<MMObjectNode> i = builder.getNodes(query).iterator();
         return i.hasNext() ?  i.next() : null;
     } catch (Exception e) {
         return null;
     }
     */
   }
 }
 private NodeMetadata createNodeWithMinecraft() {
   int javaPlusOverhead = maxHeap + 256;
   NodeMetadata node =
       nodeManager.createNodeWithAdminUserAndJDKInGroupOpeningPortAndMinRam(
           group, port, javaPlusOverhead);
   nodeManager.startDaemonOnNode(daemonFactory.get(), node.getId());
   return node;
 }
Ejemplo n.º 3
0
 protected String getProperty(Node node, String key) {
   NodeManager properties = node.getCloud().getNodeManager("properties");
   Function get = properties.getFunction("get");
   Parameters params = get.createParameters();
   params.set("node", node);
   params.set("key", key);
   return (String) get.getFunctionValue(params);
 }
Ejemplo n.º 4
0
 // old node as argument
 public void testCreateRelationToNewNode2() {
   Cloud cloud = getCloud();
   Transaction t = cloud.getTransaction("createrelationtrans");
   Node n = t.getNode(newNode);
   NodeManager urls = t.getNodeManager("urls");
   Node url = urls.createNode();
   RelationManager rm = t.getRelationManager("urls", "news", "posrel");
   Relation r = url.createRelation(n, rm);
   t.commit();
 }
Ejemplo n.º 5
0
 public void testCreateRelationBetweenNewNodes() {
   Cloud cloud = getCloud();
   Transaction t = cloud.getTransaction("createrelationtrans");
   NodeManager news = t.getNodeManager("news");
   Node n = news.createNode();
   NodeManager urls = t.getNodeManager("urls");
   Node url = urls.createNode();
   RelationManager rm = t.getRelationManager("news", "urls", "posrel");
   Relation r = n.createRelation(url, rm);
   t.commit();
 }
Ejemplo n.º 6
0
 protected void setProperty(Node node, String key, String value) {
   NodeManager properties = node.getCloud().getNodeManager("properties");
   Function set = properties.getFunction("set");
   Parameters params = set.createParameters();
   params.set("node", node);
   params.set("key", key);
   if (value.length() > 255) {
     value = value.substring(0, 255);
   }
   params.set("value", value);
   set.getFunctionValue(params);
 }
Ejemplo n.º 7
0
 public void testTransactionsAreEqual() {
   Cloud cloud = getCloud();
   Transaction t1 = cloud.getTransaction("testequals");
   Transaction t2 = cloud.getTransaction("testequals");
   assertEquals(t1, t2);
   Node n = t1.getNode(newNode);
   NodeManager urls = t2.getNodeManager("urls");
   Node url = urls.createNode();
   RelationManager rm = t2.getRelationManager("urls", "news", "posrel");
   Relation r = url.createRelation(n, rm);
   t2.commit();
   assertTrue(t2.isCommitted());
   assertTrue(t1.isCommitted());
   // assertTrue(t1 == t2); // FAILS IN RMMCI. Perhaps we should simply implement .equals on
   // transactions
 }
Ejemplo n.º 8
0
  @Override
  public void buildChildren(
      final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    final ValueDescriptorImpl parentDescriptor =
        (ValueDescriptorImpl) builder.getParentDescriptor();
    final NodeManager nodeManager = builder.getNodeManager();
    final NodeDescriptorFactory nodeDescriptorFactory = builder.getDescriptorManager();

    List<DebuggerTreeNode> children = new ArrayList<>();
    if (value instanceof ObjectReference) {
      final ObjectReference objRef = (ObjectReference) value;
      final ReferenceType refType = objRef.referenceType();
      // default ObjectReference processing
      List<Field> fields = refType.allFields();
      if (!fields.isEmpty()) {
        Set<String> names = new HashSet<>();
        for (Field field : fields) {
          if (shouldDisplay(evaluationContext, objRef, field)) {
            FieldDescriptor fieldDescriptor =
                createFieldDescriptor(
                    parentDescriptor, nodeDescriptorFactory, objRef, field, evaluationContext);
            String name = fieldDescriptor.getName();
            if (names.contains(name)) {
              fieldDescriptor.putUserData(FieldDescriptor.SHOW_DECLARING_TYPE, Boolean.TRUE);
            } else {
              names.add(name);
            }
            children.add(nodeManager.createNode(fieldDescriptor, evaluationContext));
          }
        }

        if (children.isEmpty()) {
          children.add(
              nodeManager.createMessageNode(
                  DebuggerBundle.message("message.node.class.no.fields.to.display")));
        } else if (XDebuggerSettingsManager.getInstance().getDataViewSettings().isSortValues()) {
          children.sort(NodeManagerImpl.getNodeComparator());
        }
      } else {
        children.add(
            nodeManager.createMessageNode(MessageDescriptor.CLASS_HAS_NO_FIELDS.getLabel()));
      }
    }
    builder.setChildren(children);
  }
Ejemplo n.º 9
0
  /**
   * Loads a Nodelist from file.
   *
   * @param fileLocation Location of the file in String format.
   * @return True if successful, false otherwise.
   */
  public boolean loadNodeList(String fileLocation) {
    Object loadedFile = fileManager.loadXMLFile(NodeList.class, fileLocation);

    if (loadedFile != null) {
      try {
        nodeManager.setNodeList((NodeList) loadedFile);
      } catch (ClassCastException e) {
        return false;
      }
      return true;
    } else {
      return false;
    }
  }
Ejemplo n.º 10
0
  public static void ReceiveUDP() {
    try {
      int port = 9040;

      // Create a socket to listen on the port.
      DatagramSocket dsocket = new DatagramSocket(port);

      // Create a buffer to read datagrams into. If a
      // packet is larger than this buffer, the
      // excess will simply be discarded!
      // TODO: what is the best size for this buffer?
      byte[] buffer = new byte[256];

      // Create a packet to receive data into the buffer
      DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

      // Now loop forever, waiting to receive packets and printing them.
      while (true) {
        // Wait to receive a datagram
        dsocket.receive(packet);

        // Convert the contents to a string, and display them
        String msg = new String(buffer, 0, packet.getLength());

        // assuming that I know the first 12 bytes are for IP
        // and the following 8 bytes are for score
        String IP = msg.substring(0, 13);
        byte[] resource = new byte[8];

        for (int i = 0; i < 8; ++i) {
          resource[i] = buffer[13 + i];
        }

        double score = ByteBuffer.wrap(resource).getDouble();
        NodeManager.Update(IP, score);

        // System.out.println(packet.getAddress().getHostName() + ": "
        //  + msg);

        // Reset the length of the packet before reusing it.
        packet.setLength(buffer.length);
      }
    } catch (Exception e) {
      System.err.println(e);
    }
  }
Ejemplo n.º 11
0
  /** {@inheritDoc} */
  @Override
  public ReleasableIterator<EntityContainer> iterate() {
    List<ReleasableIterator<EntityContainer>> sources;

    sources = new ArrayList<ReleasableIterator<EntityContainer>>();

    sources.add(
        new UpcastIterator<EntityContainer, NodeContainer>(
            new NodeContainerIterator(nodeManager.iterate())));
    sources.add(
        new UpcastIterator<EntityContainer, WayContainer>(
            new WayContainerIterator(wayManager.iterate())));
    sources.add(
        new UpcastIterator<EntityContainer, RelationContainer>(
            new RelationContainerIterator(relationManager.iterate())));

    return new MultipleSourceIterator<EntityContainer>(sources);
  }
Ejemplo n.º 12
0
  /**
   * 右ノードに対して近隣ノード集合を送信する. 右ノードが limit と等しいか,limit を超える場合は送信しない.
   * 送信する近隣ノード集合は,自ノードの近隣ノード集合に自分自身を加えたものである.
   *
   * @param right 右ノード
   * @param limit 送信する限界キー.
   */
  synchronized void sendRight(Link right, DdllKey limit) {
    // 以下の if 文はコメントアウトしてある.
    // 10A-20B-30B-40C (数値はkey, アルファベットは物理ノードを表す)
    // このとき,20の近隣ノード集合を30に送っておかないと,40が必要な情報を得られないため.
    // if (right.addr.equals(me.addr)) {
    // return;
    // }

    if (Node.isOrdered(key, limit, right.key)) {
      logger.debug("right node {} reached to the limit {}", right, limit);
      return;
    }

    Set<Link> propset = computeSetForRNode(true, right);
    if (right.equals(prevRight)) {
      logger.debug("me =  {}", me);
      logger.debug("propset =  {}", propset);
      logger.debug("prevset =  {}", prevset);
      if (propset.equals(prevset)) {
        return;
      }
    } else {
      logger.debug("right = {}, prevRight = {}", right, prevRight);
    }

    // return if neighbor set size == 0 (for experiments)
    if (propset.size() == 0) {
      return;
    }

    // propagate to the immediate right node
    logger.debug("propagate to right (node = {}, set = {})", right, propset);
    NodeManagerIf stub = manager.getStub(right.addr);
    try {
      stub.propagateNeighbors(right.key, propset, limit);
    } catch (RPCException e) {
      logger.info("", e);
    }
    prevRight = right;
    prevset = propset;
  }
Ejemplo n.º 13
0
 /**
  * Adds a Node to the NodeList.
  *
  * @param hostname The name of the node you want to add.
  * @param ipAddress The ip address of the node you want to add.
  * @return True if successful, false otherwise.
  */
 public boolean addNode(String hostname, String ipAddress) {
   return nodeManager.addNode(hostname, ipAddress);
 }
Ejemplo n.º 14
0
  private Boolean sendMail(HttpServletRequest req, Node node, String email) {
    boolean send = false;

    Cloud cloud = node.getCloud();
    String emailbuilder = "email";
    try {
      Module sendmail = cloud.getCloudContext().getModule("sendmail");
      emailbuilder = sendmail.getProperty("emailbuilder");
    } catch (NotFoundException nfe) {
      log.warn("No email module " + nfe);
    }

    if (cloud.hasNodeManager(emailbuilder)) {

      NodeManager nm = cloud.getNodeManager(emailbuilder);
      Node message = nm.createNode();

      String host = req.getHeader("host");
      if (host == null || "".equals(host)) {
        try {
          host = java.net.InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException uhe) {
          log.warn("No host: " + uhe);
        }
      }
      String from = "downloader@" + host;
      // do a quick check if we've got something more or less valid
      Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
      Matcher m = p.matcher(from);
      if (!m.matches()) {
        from = "*****@*****.**";
      }

      String mediaTitle = node.getStringValue("title");
      String mediaUrl = getProperty(node, URL_KEY);
      StringBuilder body = new StringBuilder();

      body.append("*This is an automated message / Dit is een geautomatiseerd bericht*");
      body.append("\n\n*English*");
      body.append("\n\nDear,");
      body.append("\n\nWe have received your file belonging to media item titled '")
          .append(mediaTitle)
          .append("'. ");
      body.append("In about 1 hour, you can find your submission at: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nKind regards,");
      body.append("\n\n").append(host);

      body.append("\n\n\n*Nederlands*");
      body.append("\n\nBeste,");
      body.append("\n\nWe hebben je bestand voor het media item met de titel '")
          .append(mediaTitle)
          .append("' ontvangen. ");
      body.append("Je kunt je bijdrage hier over circa een uur terugvinden: ");
      body.append("http://").append(host).append("/media/").append(node.getNumber());
      body.append("\n\nMet vriendelijke groet,");
      body.append("\n\n").append(host);

      message.setValue("from", from);
      message.setValue("to", email);
      message.setValue("subject", "Download complete / Download voltooid");
      message.setValue("body", body.toString());
      message.commit();

      Function mail = message.getFunction("mail");
      Parameters mail_params = mail.createParameters();
      mail_params.set("type", "oneshot");
      mail.getFunctionValue(mail_params);

      if (log.isDebugEnabled()) {
        log.debug("Message download ready send to: " + email);
      }
      send = true;
    } else {
      log.warn("Can not send message - no emailbuilder installed.");
    }

    return send;
  }
 public Map<HostAndPort, String> mapHostAndPortToStdoutForCommand(String cmd) {
   return transformKeys(
       nodeManager.stdoutFromCommandOnGroup(cmd, group), firstPublicAddressToHostAndPort(port));
 }
Ejemplo n.º 16
0
 /** {@inheritDoc} */
 @Override
 @Deprecated
 public Node getNode(long id) {
   return nodeManager.getEntity(id);
 }
 public Iterable<HostAndPort> list() {
   return transformToHostAndPort(nodeManager.listRunningNodesInGroup(group));
 }
 public void CreateTask(String compName, String topologyname, String fullClassName, int instanceId)
     throws TException {
   m_oNodeManager.CreateTask(compName, instanceId, topologyname, fullClassName);
 }
Ejemplo n.º 19
0
 /**
  * Returns the HashMap of the NodeList.
  *
  * @return HashMap A map with all the nodes.
  */
 public HashMap<Integer, Node> getNodeList() {
   return nodeManager.getNodes();
 }
Ejemplo n.º 20
0
 /**
  * Returns the node where the file can be found.
  *
  * @param filename Filename in String format.
  * @return The file owner.
  */
 public Node getFileLocation(String filename) {
   return nodeManager.getNodeList().getFileLocation(filename);
 }
Ejemplo n.º 21
0
 /**
  * Saves a node to file.
  *
  * @param fileLocation Location in String format.
  * @return True if successful, false otherwise.
  */
 public boolean saveNodeList(String fileLocation) {
   return fileManager.saveXMLFile(nodeManager.getNodeList(), fileLocation);
 }
Ejemplo n.º 22
0
  @Test
  public void testSuccessfulContainerLaunch()
      throws InterruptedException, IOException, YarnException {

    FileContext localFS = FileContext.getLocalFSFileContext();

    localFS.delete(new Path(localDir.getAbsolutePath()), true);
    localFS.delete(new Path(localLogDir.getAbsolutePath()), true);
    localFS.delete(new Path(remoteLogDir.getAbsolutePath()), true);
    localDir.mkdir();
    localLogDir.mkdir();
    remoteLogDir.mkdir();

    YarnConfiguration conf = new YarnConfiguration();

    Context context =
        new NMContext(
            new NMContainerTokenSecretManager(conf),
            new NMTokenSecretManagerInNM(),
            null,
            null,
            new NMNullStateStoreService()) {
          @Override
          public int getHttpPort() {
            return 1234;
          }
        };

    conf.set(YarnConfiguration.NM_LOCAL_DIRS, localDir.getAbsolutePath());
    conf.set(YarnConfiguration.NM_LOG_DIRS, localLogDir.getAbsolutePath());
    conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, remoteLogDir.getAbsolutePath());

    ContainerExecutor exec = new DefaultContainerExecutor();
    exec.setConf(conf);

    DeletionService del = new DeletionService(exec);
    Dispatcher dispatcher = new AsyncDispatcher();
    LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
    NodeHealthCheckerService healthChecker =
        new NodeHealthCheckerService(NodeManager.getNodeHealthScriptRunner(conf), dirsHandler);
    healthChecker.init(conf);
    NodeManagerMetrics metrics = NodeManagerMetrics.create();
    NodeStatusUpdater nodeStatusUpdater =
        new NodeStatusUpdaterImpl(context, dispatcher, healthChecker, metrics) {
          @Override
          protected ResourceTracker getRMClient() {
            return new LocalRMInterface();
          };

          @Override
          protected void stopRMProxy() {
            return;
          }

          @Override
          protected void startStatusUpdater() {
            return; // Don't start any updating thread.
          }

          @Override
          public long getRMIdentifier() {
            return SIMULATED_RM_IDENTIFIER;
          }
        };

    DummyContainerManager containerManager =
        new DummyContainerManager(
            context,
            exec,
            del,
            nodeStatusUpdater,
            metrics,
            new ApplicationACLsManager(conf),
            dirsHandler);
    nodeStatusUpdater.init(conf);
    ((NMContext) context).setContainerManager(containerManager);
    nodeStatusUpdater.start();
    containerManager.init(conf);
    containerManager.start();

    ContainerLaunchContext launchContext =
        recordFactory.newRecordInstance(ContainerLaunchContext.class);
    ApplicationId applicationId = ApplicationId.newInstance(0, 0);
    ApplicationAttemptId applicationAttemptId = ApplicationAttemptId.newInstance(applicationId, 0);
    ContainerId cID = ContainerId.newContainerId(applicationAttemptId, 0);

    String user = "******";
    StartContainerRequest scRequest =
        StartContainerRequest.newInstance(
            launchContext,
            TestContainerManager.createContainerToken(
                cID,
                SIMULATED_RM_IDENTIFIER,
                context.getNodeId(),
                user,
                context.getContainerTokenSecretManager()));
    List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
    list.add(scRequest);
    StartContainersRequest allRequests = StartContainersRequest.newInstance(list);
    containerManager.startContainers(allRequests);

    BaseContainerManagerTest.waitForContainerState(containerManager, cID, ContainerState.RUNNING);

    List<ContainerId> containerIds = new ArrayList<ContainerId>();
    containerIds.add(cID);
    StopContainersRequest stopRequest = StopContainersRequest.newInstance(containerIds);
    containerManager.stopContainers(stopRequest);
    BaseContainerManagerTest.waitForContainerState(containerManager, cID, ContainerState.COMPLETE);

    containerManager.stop();
  }
Ejemplo n.º 23
0
 /**
  * Deletes a node from the NodeList.
  *
  * @param hostname The name of the node you want to remove.
  * @return True if successful, false otherwise.
  */
 public boolean delNode(String hostname) {
   return nodeManager.delNode(hostname);
 }
 public void TransferTupleToNode(int nTuples, List<ByteBuffer> tuples) throws TException {
   // System.out.println("Received " + Integer.toString(nTuples) + " tuples");
   m_oNodeManager.ReceiveTuplesFromOutside(tuples);
 }
Ejemplo n.º 25
0
 /** Clear all nodes from the list. */
 public void clearList() {
   nodeManager.clearList();
 }
 public void StartTopology(String sTopoloogy) throws TException {
   m_oNodeManager.StartTopology(sTopoloogy);
 }
 public Iterable<HostAndPort> destroy() {
   return transformToHostAndPort(nodeManager.destroyNodesInGroup(group));
 }