当前位置: 首页>>代码示例>>Java>>正文


Java RestStatus.OK属性代码示例

本文整理汇总了Java中org.elasticsearch.rest.RestStatus.OK属性的典型用法代码示例。如果您正苦于以下问题:Java RestStatus.OK属性的具体用法?Java RestStatus.OK怎么用?Java RestStatus.OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.elasticsearch.rest.RestStatus的用法示例。


在下文中一共展示了RestStatus.OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: analyze

public ShowCreateTableAnalyzedStatement analyze(Table table, Analysis analysis) {
    TableInfo tableInfo = schemas.getTableInfo(TableIdent.of(table, analysis.parameterContext().defaultSchema()));
    if (!(tableInfo instanceof DocTableInfo)) {
        throw new UnsupportedOperationException("Table must be a doc table");
    }

    // Add SQL Authentication
    // GaoPan 2016/06/16
    AuthResult authResult = AuthService.sqlAuthenticate(analysis.parameterContext().getLoginUserContext(),
            tableInfo.ident().schema(), tableInfo.ident().name(), PrivilegeType.READ_ONLY);
    if (authResult.getStatus() != RestStatus.OK) {
        throw new NoPermissionException(authResult.getStatus().getStatus(), authResult.getMessage());
    }

    return new ShowCreateTableAnalyzedStatement((DocTableInfo) tableInfo);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:ShowCreateTableAnalyzer.java

示例2: testXContentBuilderClosedInBuildResponse

public void testXContentBuilderClosedInBuildResponse() throws Exception {
    AtomicReference<XContentBuilder> builderAtomicReference = new AtomicReference<>();
    RestBuilderListener<TransportResponse.Empty> builderListener =
        new RestBuilderListener<Empty>(new FakeRestChannel(new FakeRestRequest(), randomBoolean(), 1)) {
            @Override
            public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception {
                builderAtomicReference.set(builder);
                builder.close();
                return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
            }
    };

    builderListener.buildResponse(Empty.INSTANCE);
    assertNotNull(builderAtomicReference.get());
    assertTrue(builderAtomicReference.get().generator().isClosed());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:RestBuilderListenerTests.java

示例3: analyze

public static SetAnalyzedStatement analyze(SetStatement node, ParameterContext parameterContext) {

        // Add SQL Authentication
        // GaoPan 2016/06/16
        AuthResult authResult = AuthService.sqlAuthenticate(parameterContext.getLoginUserContext(),
                VirtualTableNames.sys.name(), VirtualTableNames.cluster.name(), PrivilegeType.READ_WRITE);
        if (authResult.getStatus() != RestStatus.OK) {
            throw new NoPermissionException(authResult.getStatus().getStatus(), authResult.getMessage());
        }

        Settings.Builder builder = Settings.builder();
        for (Assignment assignment : node.assignments()) {
            String settingsName = ExpressionToStringVisitor.convert(assignment.columnName(),
                    parameterContext.parameters());

            SettingsApplier settingsApplier = CrateSettings.getSettingsApplier(settingsName);
            for (String setting : ExpressionToSettingNameListVisitor.convert(assignment)) {
                checkIfSettingIsRuntime(setting);
            }

            settingsApplier.apply(builder, parameterContext.parameters(), assignment.expression());
        }
        return new SetAnalyzedStatement(builder.build(), node.settingType().equals(SetStatement.SettingType.PERSISTENT));
    }
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:SetStatementAnalyzer.java

示例4: visitAlterBlobTable

@Override
public AlterBlobTableAnalyzedStatement visitAlterBlobTable(AlterBlobTable node, Analysis analysis) {
    AlterBlobTableAnalyzedStatement statement = new AlterBlobTableAnalyzedStatement(schemas);

    statement.table(tableToIdent(node.table()));

    // Add SQL Authentication
    // GaoPan 2016/06/16
    AuthResult authResult = AuthService.sqlAuthenticate(analysis.parameterContext().getLoginUserContext(),
            statement.table().ident().schema(), statement.table().ident().name(), PrivilegeType.READ_WRITE);
    if (authResult.getStatus() != RestStatus.OK) {
        throw new NoPermissionException(authResult.getStatus().getStatus(), authResult.getMessage());
    }

    if (node.genericProperties().isPresent()) {
        TABLE_PROPERTIES_ANALYZER.analyze(
                statement.tableParameter(), statement.table().tableParameterInfo(),
                node.genericProperties(), analysis.parameterContext().parameters());
    } else if (!node.resetProperties().isEmpty()) {
        TABLE_PROPERTIES_ANALYZER.analyze(
                statement.tableParameter(), statement.table().tableParameterInfo(),
                node.resetProperties());
    }

    return statement;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:AlterBlobTableAnalyzer.java

示例5: indexFact

/**
 * Index a Fact into ElasticSearch.
 *
 * @param fact Fact to index
 * @return Indexed Fact
 */
public FactDocument indexFact(FactDocument fact) {
  if (fact == null || fact.getId() == null) return null;
  IndexResponse response;

  try {
    IndexRequest request = new IndexRequest(INDEX_NAME, TYPE_NAME, fact.getId().toString())
            .source(FACT_DOCUMENT_WRITER.writeValueAsBytes(encodeValues(fact)), XContentType.JSON);
    response = clientFactory.getHighLevelClient().index(request);
  } catch (IOException ex) {
    throw logAndExit(ex, String.format("Could not perform request to index Fact with id = %s.", fact.getId()));
  }

  if (response.status() != RestStatus.OK && response.status() != RestStatus.CREATED) {
    LOGGER.warning("Could not index Fact with id = %s.", fact.getId());
  } else if (response.getResult() == DocWriteResponse.Result.CREATED) {
    LOGGER.info("Successfully indexed Fact with id = %s.", fact.getId());
  } else if (response.getResult() == DocWriteResponse.Result.UPDATED) {
    LOGGER.info("Successfully re-indexed existing Fact with id = %s.", fact.getId());
  }

  return fact;
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:28,代码来源:FactSearchManager.java

示例6: status

/**
 * Returns snapshot REST status
 */
public RestStatus status() {
    if (state == SnapshotState.FAILED) {
        return RestStatus.INTERNAL_SERVER_ERROR;
    }
    if (shardFailures.size() == 0) {
        return RestStatus.OK;
    }
    return RestStatus.status(successfulShards, totalShards, shardFailures.toArray(new ShardOperationFailedException[shardFailures.size()]));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:SnapshotInfo.java

示例7: status

@Override
public RestStatus status() {
    if (hasResponse()) {
        return response.status();
    } else {
        return RestStatus.OK;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:SearchTemplateResponse.java

示例8: sendResponse

@Override
public void sendResponse(RestResponse response) {
    if (response.status() == RestStatus.OK) {
        responses.incrementAndGet();
    } else {
        errors.incrementAndGet();
    }
    latch.countDown();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:FakeRestChannel.java

示例9: convertMainResponse

static BytesRestResponse convertMainResponse(MainResponse response, RestRequest request, XContentBuilder builder) throws IOException {
    RestStatus status = response.isAvailable() ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;

    // Default to pretty printing, but allow ?pretty=false to disable
    if (request.hasParam("pretty") == false) {
        builder.prettyPrint().lfAtEnd();
    }
    response.toXContent(builder, request);
    return new BytesRestResponse(status, builder);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:RestMainAction.java

示例10: status

/**
 * Returns snapshot REST status
 */
public RestStatus status() {
    if (state == SnapshotState.FAILED) {
        return RestStatus.INTERNAL_SERVER_ERROR;
    }
    if (shardFailures.size() == 0) {
        return RestStatus.OK;
    }
    return RestStatus.status(successfulShards, totalShards,
                             shardFailures.toArray(new ShardOperationFailedException[shardFailures.size()]));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:SnapshotInfo.java

示例11: visitCreateBlobTable

@Override
public CreateBlobTableAnalyzedStatement visitCreateBlobTable(CreateBlobTable node, Analysis analysis) {
    CreateBlobTableAnalyzedStatement statement = new CreateBlobTableAnalyzedStatement();
    TableIdent tableIdent = tableToIdent(node.name());

    // Add SQL Authentication
    // GaoPan 2016/06/16
    AuthResult authResult = AuthService.sqlAuthenticate(analysis.parameterContext().getLoginUserContext(),
            tableIdent.schema(), null, PrivilegeType.READ_WRITE);
    if (authResult.getStatus() != RestStatus.OK) {
        throw new NoPermissionException(authResult.getStatus().getStatus(), authResult.getMessage());
    }

    statement.table(tableIdent, schemas);

    int numShards;
    if (node.clusteredBy().isPresent()) {
        numShards = numberOfShards.fromClusteredByClause(
                node.clusteredBy().get(),
                analysis.parameterContext().parameters()
        );
    } else {
        numShards = numberOfShards.defaultNumberOfShards();
    }
    statement.tableParameter().settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards);

    // apply default in case it is not specified in the genericProperties,
    // if it is it will get overwritten afterwards.
    TABLE_PROPERTIES_ANALYZER.analyze(
            statement.tableParameter(), new BlobTableParameterInfo(),
            node.genericProperties(), analysis.parameterContext().parameters(), true);

    return statement;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:CreateBlobTableStatementAnalyzer.java

示例12: searchFacts

/**
 * Search for Facts indexed in ElasticSearch by a given search criteria. Only Facts satisfying the search criteria
 * will be returned. Returns an empty list if no Fact satisfies the search criteria.
 * <p>
 * Both 'currentUserID' (identifying the calling user) and 'availableOrganizationID' (identifying the Organizations
 * the calling user has access to) must be set in the search criteria in order to apply access control to Facts. Only
 * Facts accessible to the calling user will be returned.
 *
 * @param criteria Search criteria to match against Facts
 * @return Facts satisfying search Criteria
 */
public List<FactDocument> searchFacts(FactSearchCriteria criteria) {
  List<FactDocument> result = ListUtils.list();
  if (criteria == null) return result;

  SearchResponse response;
  try {
    response = clientFactory.getHighLevelClient().search(buildSearchRequest(criteria));
  } catch (IOException ex) {
    throw logAndExit(ex, "Could not perform request to search for Facts.");
  }

  if (response.status() != RestStatus.OK) {
    LOGGER.warning("Could not search for Facts (response code %s).", response.status());
    return result;
  }

  for (SearchHit hit : response.getHits()) {
    FactDocument document = decodeFactDocument(UUID.fromString(hit.getId()), toBytes(hit.getSourceRef()));
    if (document != null) {
      result.add(document);
    }
  }

  LOGGER.info("Successfully retrieved %d Facts.", result.size());
  return result;
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:37,代码来源:FactSearchManager.java

示例13: visitRefreshStatement

@Override
public RefreshTableAnalyzedStatement visitRefreshStatement(RefreshStatement node, Analysis analysis) {
    Set<String> indexNames = new HashSet<>(node.tables().size());
    for (Table nodeTable : node.tables()) {
        TableInfo tableInfo = schemas.getTableInfo(
                TableIdent.of(nodeTable, analysis.parameterContext().defaultSchema()));
        Preconditions.checkArgument(tableInfo instanceof DocTableInfo,
                "table '%s' cannot be refreshed",
                tableInfo.ident().fqn());

        // Add SQL Authentication
        // GaoPan 2016/06/16
        AuthResult authResult = AuthService.sqlAuthenticate(analysis.parameterContext().getLoginUserContext(),
                tableInfo.ident().schema(), tableInfo.ident().name(), PrivilegeType.READ_WRITE);
        if (authResult.getStatus() != RestStatus.OK) {
            throw new NoPermissionException(authResult.getStatus().getStatus(), authResult.getMessage());
        }

        if (nodeTable.partitionProperties().isEmpty()) {
            indexNames.addAll(Arrays.asList(((DocTableInfo) tableInfo).concreteIndices()));
        } else {
            DocTableInfo docTableInfo = (DocTableInfo) tableInfo;
            PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(
                    docTableInfo,
                    nodeTable.partitionProperties(),
                    analysis.parameterContext().parameters()
            );
            if (!docTableInfo.partitions().contains(partitionName)) {
                throw new PartitionUnknownException(tableInfo.ident().fqn(), partitionName.ident());
            }
            indexNames.add(partitionName.asIndexName());
        }
    }
    return new RefreshTableAnalyzedStatement(indexNames);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:35,代码来源:RefreshTableAnalyzer.java

示例14: buildResponse

@Override
public RestResponse buildResponse(GetIndexResponse getIndexResponse, XContentBuilder builder) throws Exception {
    GetIndexRequest.Feature[] features = getIndexRequest.features();
    String[] indices = getIndexResponse.indices();

    builder.startObject();
    for (String index : indices) {
        builder.startObject(index);
        for (GetIndexRequest.Feature feature : features) {
            switch (feature) {
                case ALIASES:
                    writeAliases(getIndexResponse.aliases().get(index), builder, channel.request());
                    break;
                case MAPPINGS:
                    writeMappings(getIndexResponse.mappings().get(index), builder, channel.request());
                    break;
                case SETTINGS:
                    writeSettings(getIndexResponse.settings().get(index), builder, channel.request());
                    break;
                default:
                    throw new IllegalStateException("feature [" + feature + "] is not valid");
            }
        }
        builder.endObject();

    }
    builder.endObject();

    return new BytesRestResponse(RestStatus.OK, builder);
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:30,代码来源:GetIndexRequestRestListener.java

示例15: testGetResponse

public void testGetResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final boolean prettyPrint = randomBoolean();

    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();

    Map<String, String> params = new HashMap<>();
    if (prettyPrint == false) {
        params.put("pretty", String.valueOf(prettyPrint));
    }
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();

    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());
    assertThat(response.content().length(), greaterThan(0));

    XContentBuilder responseBuilder = JsonXContent.contentBuilder();
    if (prettyPrint) {
        // do this to mimic what the rest layer does
        responseBuilder.prettyPrint().lfAtEnd();
    }
    mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
    BytesReference xcontentBytes = responseBuilder.bytes();
    assertEquals(xcontentBytes, response.content());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:RestMainActionTests.java


注:本文中的org.elasticsearch.rest.RestStatus.OK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。