Search in sources :

Example 1 with Server

use of org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server in project pentaho-kettle by pentaho.

the class ElasticSearchBulkDialog method test.

private void test(TestType testType) {
    try {
        ElasticSearchBulkMeta tempMeta = new ElasticSearchBulkMeta();
        toModel(tempMeta);
        // if ( !tempMeta.getServers().isEmpty() ) {
        Settings.Builder settingsBuilder = Settings.builder();
        settingsBuilder.put(Settings.Builder.EMPTY_SETTINGS);
        tempMeta.getSettingsMap().entrySet().stream().forEach((s) -> settingsBuilder.put(s.getKey(), transMeta.environmentSubstitute(s.getValue())));
        try (PreBuiltTransportClient client = new PreBuiltTransportClient(settingsBuilder.build())) {
            for (Server server : tempMeta.getServers()) {
                client.addTransportAddress(new TransportAddress(InetAddress.getByName(transMeta.environmentSubstitute(server.getAddress())), server.getPort()));
            }
            AdminClient admin = client.admin();
            switch(testType) {
                case INDEX:
                    if (StringUtils.isBlank(tempMeta.getIndex())) {
                        showError(BaseMessages.getString(PKG, "ElasticSearchBulk.Error.NoIndex"));
                        break;
                    }
                    // First check to see if the index exists
                    IndicesExistsRequestBuilder indicesExistBld = admin.indices().prepareExists(tempMeta.getIndex());
                    IndicesExistsResponse indicesExistResponse = indicesExistBld.execute().get();
                    if (!indicesExistResponse.isExists()) {
                        showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoIndex"));
                        return;
                    }
                    RecoveryRequestBuilder indicesBld = admin.indices().prepareRecoveries(tempMeta.getIndex());
                    ActionFuture<RecoveryResponse> lafInd = indicesBld.execute();
                    String shards = "" + lafInd.get().getSuccessfulShards() + "/" + lafInd.get().getTotalShards();
                    showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", shards));
                    break;
                case CLUSTER:
                    ClusterStateRequestBuilder clusterBld = admin.cluster().prepareState();
                    ActionFuture<ClusterStateResponse> lafClu = clusterBld.execute();
                    ClusterStateResponse cluResp = lafClu.actionGet();
                    String name = cluResp.getClusterName().value();
                    ClusterState cluState = cluResp.getState();
                    int numNodes = cluState.getNodes().getSize();
                    showMessage(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.TestCluster.TestOK", name, numNodes));
                    break;
                default:
                    break;
            }
        }
    } catch (NoNodeAvailableException | MasterNotDiscoveredException e) {
        showError(BaseMessages.getString(PKG, "ElasticSearchBulkDialog.Error.NoNodesFound"));
    } catch (Exception e) {
        showError(e.getLocalizedMessage());
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Server(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequestBuilder(org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) MasterNotDiscoveredException(org.elasticsearch.discovery.MasterNotDiscoveredException) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) KettleException(org.pentaho.di.core.exception.KettleException) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) IndicesExistsRequestBuilder(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) RecoveryRequestBuilder(org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder) ElasticSearchBulkMeta(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta) Settings(org.elasticsearch.common.settings.Settings) AdminClient(org.elasticsearch.client.AdminClient)

Example 2 with Server

use of org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server in project pentaho-kettle by pentaho.

the class ElasticSearchBulk method initClient.

private void initClient() throws UnknownHostException {
    Settings.Builder settingsBuilder = Settings.builder();
    settingsBuilder.put(Settings.Builder.EMPTY_SETTINGS);
    meta.getSettingsMap().entrySet().stream().forEach((s) -> settingsBuilder.put(s.getKey(), environmentSubstitute(s.getValue())));
    PreBuiltTransportClient tClient = new PreBuiltTransportClient(settingsBuilder.build());
    for (Server server : meta.getServers()) {
        tClient.addTransportAddress(new TransportAddress(InetAddress.getByName(environmentSubstitute(server.getAddress())), server.getPort()));
    }
    client = tClient;
/**
 * With the upgrade to elasticsearch 6.3.0, removed the NodeBuilder,
 *  which was removed from the elasticsearch 5.0 API, see:
 *  https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_java_api_changes
 *  .html#_nodebuilder_removed
 */
}
Also used : PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) Server(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Example 3 with Server

use of org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server in project pentaho-kettle by pentaho.

the class ElasticSearchBulkDialog method getData.

/**
 * Read the data from the ElasticSearchBulkMeta object and show it in this dialog.
 *
 * @param in The ElasticSearchBulkMeta object to obtain the data from.
 */
public void getData(ElasticSearchBulkMeta in) {
    wIndex.setText(Const.NVL(in.getIndex(), ""));
    wType.setText(Const.NVL(in.getType(), ""));
    wBatchSize.setText(Const.NVL(in.getBatchSize(), "" + ElasticSearchBulkMeta.DEFAULT_BATCH_SIZE));
    wStopOnError.setSelection(in.isStopOnError());
    wTimeOut.setText(Const.NVL(in.getTimeOut(), ""));
    wTimeOut.setTimeUnit(in.getTimeoutUnit());
    wIdInField.setText(Const.NVL(in.getIdInField(), ""));
    wIsOverwrite.setSelection(in.isOverWriteIfSameId());
    wIsJson.setSelection(in.isJsonInsert());
    wJsonField.setText(Const.NVL(in.getJsonField(), ""));
    // listener not working here
    wJsonField.setEnabled(wIsJson.getSelection());
    wUseOutput.setSelection(in.isUseOutput());
    wIdOutField.setText(Const.NVL(in.getIdOutField(), ""));
    // listener not working here
    wIdOutField.setEnabled(wUseOutput.getSelection());
    // Fields
    mapToTableView(model.getFieldsMap(), wFields);
    // Servers
    for (ElasticSearchBulkMeta.Server server : model.getServers()) {
        wServers.add(server.address, "" + server.port);
    }
    wServers.removeEmptyRows();
    wServers.setRowNums();
    // Settings
    mapToTableView(model.getSettingsMap(), wSettings);
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : Server(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server) ElasticSearchBulkMeta(org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta)

Aggregations

Server (org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server)3 Settings (org.elasticsearch.common.settings.Settings)2 TransportAddress (org.elasticsearch.common.transport.TransportAddress)2 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)2 ElasticSearchBulkMeta (org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta)2 ClusterStateRequestBuilder (org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 IndicesExistsRequestBuilder (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder)1 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)1 RecoveryRequestBuilder (org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder)1 RecoveryResponse (org.elasticsearch.action.admin.indices.recovery.RecoveryResponse)1 AdminClient (org.elasticsearch.client.AdminClient)1 NoNodeAvailableException (org.elasticsearch.client.transport.NoNodeAvailableException)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 MasterNotDiscoveredException (org.elasticsearch.discovery.MasterNotDiscoveredException)1 KettleException (org.pentaho.di.core.exception.KettleException)1