private static List<Throwable> putTemplate(PutRequest request) {
    MetaDataCreateIndexService createIndexService =
        new MetaDataCreateIndexService(
            Settings.EMPTY,
            null,
            null,
            null,
            null,
            null,
            Version.CURRENT,
            null,
            Sets.<IndexTemplateFilter>newHashSet(),
            null,
            null);
    MetaDataIndexTemplateService service =
        new MetaDataIndexTemplateService(Settings.EMPTY, null, createIndexService, null);

    final List<Throwable> throwables = new ArrayList<>();
    service.putTemplate(
        request,
        new MetaDataIndexTemplateService.PutListener() {
          @Override
          public void onResponse(MetaDataIndexTemplateService.PutResponse response) {}

          @Override
          public void onFailure(Throwable t) {
            throwables.add(t);
          }
        });

    return throwables;
  }
  @Override
  protected void masterOperation(
      final PutIndexTemplateRequest request,
      final ClusterState state,
      final ActionListener<PutIndexTemplateResponse> listener) {
    String cause = request.cause();
    if (cause.length() == 0) {
      cause = "api";
    }

    indexTemplateService.putTemplate(
        new MetaDataIndexTemplateService.PutRequest(cause, request.name())
            .template(request.template())
            .order(request.order())
            .settings(request.settings())
            .mappings(request.mappings())
            .aliases(request.aliases())
            .customs(request.customs())
            .create(request.create())
            .masterTimeout(request.masterNodeTimeout()),
        new MetaDataIndexTemplateService.PutListener() {
          @Override
          public void onResponse(MetaDataIndexTemplateService.PutResponse response) {
            listener.onResponse(new PutIndexTemplateResponse(response.acknowledged()));
          }

          @Override
          public void onFailure(Throwable t) {
            logger.debug("failed to put template [{}]", t, request.name());
            listener.onFailure(t);
          }
        });
  }