@Override
 public void readProperties(Map<Integer, Object> props, boolean partial) {
   if (!partial || props.containsKey(SUB_TYPE))
     setType(Values.toString(MapUtils.getObject(props, SUB_TYPE, "")));
   if (!partial || props.containsKey(SUB_INFO))
     setInfo(Values.toString(MapUtils.getObject(props, SUB_INFO, "")));
   if (!partial || props.containsKey(SUB_INFO))
     flag = (int) Values.toInt(MapUtils.getObject(props, SUB_FLAG, "0"));
   if (!partial || props.containsKey(SUB_LABEL))
     setLabel(Values.toString(MapUtils.getObject(props, SUB_LABEL, "")));
 }
Exemple #2
0
  /** Generates the list of individual deploy actions that has to be sent to each DNode. */
  private static Map<String, List<DeployAction>> generateDeployActionsPerDNode(
      List<DeployRequest> deployRequests, long version) {
    HashMap<String, List<DeployAction>> actions = new HashMap<String, List<DeployAction>>();

    long deployDate =
        System
            .currentTimeMillis(); // Here is where we decide the data of the deployment for all
                                  // deployed tablespaces

    for (DeployRequest req : deployRequests) {
      for (Object obj : req.getReplicationMap()) {
        ReplicationEntry rEntry = (ReplicationEntry) obj;
        PartitionEntry pEntry = null;
        for (PartitionEntry partEntry : req.getPartitionMap()) {
          if (partEntry.getShard() == rEntry.getShard()) {
            pEntry = partEntry;
          }
        }
        if (pEntry == null) {
          throw new RuntimeException(
              "No Partition metadata for shard: "
                  + rEntry.getShard()
                  + " this is very likely to be a software bug.");
        }
        // Normalize DNode ids -> The convention is that DNodes are identified by host:port . So we
        // need to strip the
        // protocol, if any
        for (int i = 0; i < rEntry.getNodes().size(); i++) {
          String dnodeId = rEntry.getNodes().get(i);
          if (dnodeId.startsWith("tcp://")) {
            dnodeId = dnodeId.substring("tcp://".length(), dnodeId.length());
          }
          rEntry.getNodes().set(i, dnodeId);
        }
        for (String dNode : rEntry.getNodes()) {
          List<DeployAction> actionsSoFar =
              (List<DeployAction>)
                  MapUtils.getObject(actions, dNode, new ArrayList<DeployAction>());
          actions.put(dNode, actionsSoFar);
          DeployAction deployAction = new DeployAction();
          deployAction.setDataURI(req.getData_uri() + "/" + rEntry.getShard() + ".db");
          deployAction.setTablespace(req.getTablespace());
          deployAction.setVersion(version);
          deployAction.setPartition(rEntry.getShard());

          // Add partition metadata to the deploy action for DNodes to save it
          PartitionMetadata metadata = new PartitionMetadata();
          metadata.setMinKey(pEntry.getMin());
          metadata.setMaxKey(pEntry.getMax());
          metadata.setNReplicas(rEntry.getNodes().size());
          metadata.setDeploymentDate(deployDate);
          metadata.setInitStatements(req.getInitStatements());

          deployAction.setMetadata(metadata);
          actionsSoFar.add(deployAction);
        }
      }
    }
    return actions;
  }