Exemplo n.º 1
0
    public static void toXContent(
        MetaData metaData, XContentBuilder builder, ToXContent.Params params) throws IOException {
      XContentContext context = XContentContext.valueOf(params.param(CONTEXT_MODE_PARAM, "API"));

      builder.startObject("meta-data");

      builder.field("version", metaData.version());
      builder.field("cluster_uuid", metaData.clusterUUID);

      if (!metaData.persistentSettings().getAsMap().isEmpty()) {
        builder.startObject("settings");
        for (Map.Entry<String, String> entry :
            metaData.persistentSettings().getAsMap().entrySet()) {
          builder.field(entry.getKey(), entry.getValue());
        }
        builder.endObject();
      }

      if (context == XContentContext.API && !metaData.transientSettings().getAsMap().isEmpty()) {
        builder.startObject("transient_settings");
        for (Map.Entry<String, String> entry : metaData.transientSettings().getAsMap().entrySet()) {
          builder.field(entry.getKey(), entry.getValue());
        }
        builder.endObject();
      }

      builder.startObject("templates");
      for (ObjectCursor<IndexTemplateMetaData> cursor : metaData.templates().values()) {
        IndexTemplateMetaData.Builder.toXContent(cursor.value, builder, params);
      }
      builder.endObject();

      if (context == XContentContext.API && !metaData.indices().isEmpty()) {
        builder.startObject("indices");
        for (IndexMetaData indexMetaData : metaData) {
          IndexMetaData.Builder.toXContent(indexMetaData, builder, params);
        }
        builder.endObject();
      }

      for (ObjectObjectCursor<String, Custom> cursor : metaData.customs()) {
        Custom proto = lookupPrototypeSafe(cursor.key);
        if (proto.context().contains(context)) {
          builder.startObject(cursor.key);
          cursor.value.toXContent(builder, params);
          builder.endObject();
        }
      }
      builder.endObject();
    }
Exemplo n.º 2
0
 public static boolean isGlobalStateEquals(MetaData metaData1, MetaData metaData2) {
   if (!metaData1.persistentSettings.equals(metaData2.persistentSettings)) {
     return false;
   }
   if (!metaData1.templates.equals(metaData2.templates())) {
     return false;
   }
   // Check if any persistent metadata needs to be saved
   int customCount1 = 0;
   for (ObjectObjectCursor<String, Custom> cursor : metaData1.customs) {
     if (customPrototypes.get(cursor.key).context().contains(XContentContext.GATEWAY)) {
       if (!cursor.value.equals(metaData2.custom(cursor.key))) return false;
       customCount1++;
     }
   }
   int customCount2 = 0;
   for (ObjectObjectCursor<String, Custom> cursor : metaData2.customs) {
     if (customPrototypes.get(cursor.key).context().contains(XContentContext.GATEWAY)) {
       customCount2++;
     }
   }
   if (customCount1 != customCount2) return false;
   return true;
 }