コード例 #1
0
 public static Settings readSettingsFromStream(StreamInput in) throws IOException {
   Builder builder = new Builder();
   int numberOfSettings = in.readVInt();
   for (int i = 0; i < numberOfSettings; i++) {
     builder.put(in.readString(), in.readString());
   }
   return builder.build();
 }
コード例 #2
0
 private ImmutableSetMultimap<V, K> invert() {
   Builder<V, K> builder = builder();
   for (Entry<K, V> entry : entries()) {
     builder.put(entry.getValue(), entry.getKey());
   }
   ImmutableSetMultimap<V, K> invertedMultimap = builder.build();
   invertedMultimap.inverse = this;
   return invertedMultimap;
 }
コード例 #3
0
 public DiscoveryNodes removeDeadMembers(Set<String> newNodes, String masterNodeId) {
   Builder builder = new Builder().masterNodeId(masterNodeId).localNodeId(localNodeId);
   for (DiscoveryNode node : this) {
     if (newNodes.contains(node.id())) {
       builder.put(node);
     }
   }
   return builder.build();
 }
コード例 #4
0
 @Override
 public MetaData readFrom(StreamInput in) throws IOException {
   Builder builder = new Builder();
   builder.version = in.readLong();
   builder.clusterUUID = in.readString();
   builder.transientSettings(readSettingsFromStream(in));
   builder.persistentSettings(readSettingsFromStream(in));
   int size = in.readVInt();
   for (int i = 0; i < size; i++) {
     builder.put(IndexMetaData.Builder.readFrom(in), false);
   }
   size = in.readVInt();
   for (int i = 0; i < size; i++) {
     builder.put(IndexTemplateMetaData.Builder.readFrom(in));
   }
   int customSize = in.readVInt();
   for (int i = 0; i < customSize; i++) {
     String type = in.readString();
     Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in);
     builder.putCustom(type, customIndexMetaData);
   }
   return builder.build();
 }
コード例 #5
0
 @Override
 public Settings getByPrefix(String prefix) {
   Builder builder = new Builder();
   for (Map.Entry<String, String> entry : getAsMap().entrySet()) {
     if (entry.getKey().startsWith(prefix)) {
       if (entry.getKey().length() < prefix.length()) {
         // ignore this one
         continue;
       }
       builder.put(entry.getKey().substring(prefix.length()), entry.getValue());
     }
   }
   builder.classLoader(classLoader);
   return builder.build();
 }
コード例 #6
0
 public static DiscoveryNodes readFrom(StreamInput in, @Nullable DiscoveryNode localNode)
     throws IOException {
   Builder builder = new Builder();
   if (in.readBoolean()) {
     builder.masterNodeId(in.readUTF());
   }
   if (localNode != null) {
     builder.localNodeId(localNode.id());
   }
   int size = in.readVInt();
   for (int i = 0; i < size; i++) {
     DiscoveryNode node = DiscoveryNode.readNode(in);
     if (localNode != null && node.id().equals(localNode.id())) {
       // reuse the same instance of our address and local node id for faster equality
       node = localNode;
     }
     builder.put(node);
   }
   return builder.build();
 }
コード例 #7
0
 Object createMap(Builder<Object, Object> builder) {
   for (int i = 0; i < keys.length; i++) {
     builder.put(keys[i], values[i]);
   }
   return builder.build();
 }
コード例 #8
0
    public static MetaData fromXContent(XContentParser parser) throws IOException {
      Builder builder = new Builder();

      // we might get here after the meta-data element, or on a fresh parser
      XContentParser.Token token = parser.currentToken();
      String currentFieldName = parser.currentName();
      if (!"meta-data".equals(currentFieldName)) {
        token = parser.nextToken();
        if (token == XContentParser.Token.START_OBJECT) {
          // move to the field name (meta-data)
          token = parser.nextToken();
          if (token != XContentParser.Token.FIELD_NAME) {
            throw new IllegalArgumentException("Expected a field name but got " + token);
          }
          // move to the next object
          token = parser.nextToken();
        }
        currentFieldName = parser.currentName();
      }

      if (!"meta-data".equals(parser.currentName())) {
        throw new IllegalArgumentException(
            "Expected [meta-data] as a field name but got " + currentFieldName);
      }
      if (token != XContentParser.Token.START_OBJECT) {
        throw new IllegalArgumentException("Expected a START_OBJECT but got " + token);
      }

      while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
          currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
          if ("settings".equals(currentFieldName)) {
            builder.persistentSettings(
                Settings.settingsBuilder()
                    .put(SettingsLoader.Helper.loadNestedFromMap(parser.mapOrdered()))
                    .build());
          } else if ("indices".equals(currentFieldName)) {
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
              builder.put(IndexMetaData.Builder.fromXContent(parser), false);
            }
          } else if ("templates".equals(currentFieldName)) {
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
              builder.put(IndexTemplateMetaData.Builder.fromXContent(parser, parser.currentName()));
            }
          } else {
            // check if its a custom index metadata
            Custom proto = lookupPrototype(currentFieldName);
            if (proto == null) {
              // TODO warn
              parser.skipChildren();
            } else {
              Custom custom = proto.fromXContent(parser);
              builder.putCustom(custom.type(), custom);
            }
          }
        } else if (token.isValue()) {
          if ("version".equals(currentFieldName)) {
            builder.version = parser.longValue();
          } else if ("cluster_uuid".equals(currentFieldName) || "uuid".equals(currentFieldName)) {
            builder.clusterUUID = parser.text();
          } else {
            throw new IllegalArgumentException("Unexpected field [" + currentFieldName + "]");
          }
        } else {
          throw new IllegalArgumentException("Unexpected token " + token);
        }
      }
      return builder.build();
    }