1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
| package org.pentaho.di.ui.trans.steps.elasticsearchbulk;
import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.ShellAdapter; import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.core.MainResponse; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.pentaho.di.core.Const; import org.pentaho.di.core.Props; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.row.RowMetaInterface; import org.pentaho.di.i18n.BaseMessages; import org.pentaho.di.trans.TransMeta; import org.pentaho.di.trans.step.BaseStepMeta; import org.pentaho.di.trans.step.StepDialogInterface; import org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta; import org.pentaho.di.trans.steps.elasticsearchbulk.ElasticSearchBulkMeta.Server; import org.pentaho.di.ui.core.dialog.ErrorDialog; import org.pentaho.di.ui.core.widget.ColumnInfo; import org.pentaho.di.ui.core.widget.LabelComboVar; import org.pentaho.di.ui.core.widget.LabelTextVar; import org.pentaho.di.ui.core.widget.TableView; import org.pentaho.di.ui.core.widget.TextVar; import org.pentaho.di.ui.trans.step.BaseStepDialog; public class ElasticSearchBulkDialog extends BaseStepDialog implements StepDialogInterface { private ElasticSearchBulkMeta model; private static Class<?> PKG = ElasticSearchBulkMeta.class; private CTabFolder wTabFolder; private FormData fdTabFolder; private CTabItem wGeneralTab; private Composite wGeneralComp; private FormData fdGeneralComp; private Label wlBatchSize; private TextVar wBatchSize; private LabelTextVar wIdOutField; private Group wIndexGroup; private FormData fdIndexGroup; private Group wSettingsGroup; private FormData fdSettingsGroup; private String[] fieldNames; private CTabItem wFieldsTab; private LabelTextVar wIndex; private LabelTextVar wType; private ModifyListener lsMod; private Button wIsJson; private Label wlIsJson; private Label wlUseOutput; private Button wUseOutput; private LabelComboVar wJsonField; private TableView wFields; private CTabItem wServersTab; private TableView wServers; private CTabItem wSettingsTab; private TableView wSettings; private LabelTimeComposite wTimeOut; private Label wlStopOnError; private Button wStopOnError; private Button wTest; private Button wTestCl; private LabelComboVar wIdInField; private Button wIsOverwrite; private Label wlIsOverwrite; public ElasticSearchBulkDialog( Shell parent, Object in, TransMeta transMeta, String sname ) { super( parent, (BaseStepMeta) in, transMeta, sname ); model = (ElasticSearchBulkMeta) in; } @Override public String open() { Shell parent = getParent(); Display display = parent.getDisplay(); shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN ); props.setLook( shell ); setShellImage( shell, model ); lsMod = new ModifyListener() { @Override public void modifyText(ModifyEvent e ) { model.setChanged(); } }; changed = model.hasChanged(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; shell.setLayout( formLayout ); shell.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.DialogTitle" ) ); int middle = props.getMiddlePct(); int margin = Const.MARGIN; wlStepname = new Label( shell, SWT.RIGHT ); wlStepname.setText( BaseMessages.getString( PKG, "System.Label.StepName" ) ); props.setLook( wlStepname ); fdlStepname = new FormData(); fdlStepname.left = new FormAttachment( 0, 0 ); fdlStepname.top = new FormAttachment( 0, margin ); fdlStepname.right = new FormAttachment( middle, -margin ); wlStepname.setLayoutData( fdlStepname ); wStepname = new Text( shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); wStepname.setText( stepname ); props.setLook( wStepname ); wStepname.addModifyListener( lsMod ); fdStepname = new FormData(); fdStepname.left = new FormAttachment( middle, 0 ); fdStepname.top = new FormAttachment( 0, margin ); fdStepname.right = new FormAttachment( 100, 0 ); wStepname.setLayoutData( fdStepname ); wTabFolder = new CTabFolder( shell, SWT.BORDER ); props.setLook( wTabFolder, Props.WIDGET_STYLE_TAB ); addGeneralTab(); addServersTab(); addFieldsTab(); addSettingsTab(); wOK = new Button( shell, SWT.PUSH ); wOK.setText( BaseMessages.getString( PKG, "System.Button.OK" ) ); wCancel = new Button( shell, SWT.PUSH ); wCancel.setText( BaseMessages.getString( PKG, "System.Button.Cancel" ) ); setButtonPositions( new Button[]{wOK, wCancel}, margin, null ); fdTabFolder = new FormData(); fdTabFolder.left = new FormAttachment( 0, 0 ); fdTabFolder.top = new FormAttachment( wStepname, margin ); fdTabFolder.right = new FormAttachment( 100, 0 ); fdTabFolder.bottom = new FormAttachment( wOK, -margin ); wTabFolder.setLayoutData( fdTabFolder ); addStandardListeners(); wTabFolder.setSelection( 0 ); setSize(); getData( model ); model.setChanged( changed ); shell.open(); while ( !shell.isDisposed() ) { if ( !display.readAndDispatch() ) { display.sleep(); } } return stepname; } private void addStandardListeners() { lsOK = new Listener() { @Override public void handleEvent(Event e ) { ok(); } }; lsCancel = new Listener() { @Override public void handleEvent(Event e ) { cancel(); } }; lsMod = new ModifyListener() { @Override public void modifyText(ModifyEvent event ) { model.setChanged(); } }; wOK.addListener( SWT.Selection, lsOK ); wCancel.addListener( SWT.Selection, lsCancel ); lsDef = new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e ) { ok(); } }; wStepname.addSelectionListener( lsDef ); shell.addShellListener( new ShellAdapter() { @Override public void shellClosed(ShellEvent e ) { cancel(); } } ); }
private void addGeneralTab() { wGeneralTab = new CTabItem( wTabFolder, SWT.NONE ); wGeneralTab.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.General.Tab" ) ); wGeneralComp = new Composite( wTabFolder, SWT.NONE ); props.setLook( wGeneralComp ); FormLayout generalLayout = new FormLayout(); generalLayout.marginWidth = 3; generalLayout.marginHeight = 3; wGeneralComp.setLayout( generalLayout ); fillIndexGroup( wGeneralComp ); fillOptionsGroup( wGeneralComp ); fdGeneralComp = new FormData(); fdGeneralComp.left = new FormAttachment( 0, 0 ); fdGeneralComp.top = new FormAttachment( wStepname, Const.MARGIN ); fdGeneralComp.right = new FormAttachment( 100, 0 ); fdGeneralComp.bottom = new FormAttachment( 100, 0 ); wGeneralComp.setLayoutData( fdGeneralComp ); wGeneralComp.layout(); wGeneralTab.setControl( wGeneralComp ); } private void fillIndexGroup( Composite parentTab ) { wIndexGroup = new Group( parentTab, SWT.SHADOW_NONE ); props.setLook( wIndexGroup ); wIndexGroup.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IndexGroup.Label" ) ); FormLayout indexGroupLayout = new FormLayout(); indexGroupLayout.marginWidth = 10; indexGroupLayout.marginHeight = 10; wIndexGroup.setLayout( indexGroupLayout ); wIndex = new LabelTextVar( transMeta, wIndexGroup, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Index" + ".Label" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Index.Tooltip" ) ); wIndex.addModifyListener( lsMod ); wType = new LabelTextVar( transMeta, wIndexGroup, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Type" + ".Label" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Type.Tooltip" ) ); wType.addModifyListener( lsMod ); wTest = new Button( wIndexGroup, SWT.PUSH ); wTest.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestIndex.Label" ) ); wTest.setToolTipText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestIndex.Tooltip" ) ); wTest.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event arg0 ) { test( TestType.INDEX ); } } ); Control[] connectionControls = new Control[]{wIndex, wType}; placeControls( wIndexGroup, connectionControls ); BaseStepDialog.positionBottomButtons( wIndexGroup, new Button[]{wTest}, Const.MARGIN, wType ); fdIndexGroup = new FormData(); fdIndexGroup.left = new FormAttachment( 0, Const.MARGIN ); fdIndexGroup.top = new FormAttachment( wStepname, Const.MARGIN ); fdIndexGroup.right = new FormAttachment( 100, -Const.MARGIN ); wIndexGroup.setLayoutData( fdIndexGroup ); } private void addServersTab() { wServersTab = new CTabItem( wTabFolder, SWT.NONE ); wServersTab.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.ServersTab.TabTitle" ) ); FormLayout serversLayout = new FormLayout(); serversLayout.marginWidth = Const.FORM_MARGIN; serversLayout.marginHeight = Const.FORM_MARGIN; Composite wServersComp = new Composite( wTabFolder, SWT.NONE ); wServersComp.setLayout( serversLayout ); props.setLook( wServersComp ); wTestCl = new Button( wServersComp, SWT.PUSH ); wTestCl.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestCluster.Label" ) ); wTestCl.setToolTipText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestCluster.Tooltip" ) ); wTestCl.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event arg0 ) { test( TestType.CLUSTER ); } } ); setButtonPositions( new Button[]{wTestCl}, Const.MARGIN, null ); ColumnInfo[] columnsMeta = new ColumnInfo[2]; columnsMeta[0] = new ColumnInfo( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.ServersTab.Address.Column" ), ColumnInfo.COLUMN_TYPE_TEXT, false ); columnsMeta[0].setUsingVariables( true ); columnsMeta[1] = new ColumnInfo( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.ServersTab.Port.Column" ), ColumnInfo.COLUMN_TYPE_TEXT, true ); wServers = new TableView( transMeta, wServersComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, columnsMeta, 1, lsMod, props ); FormData fdServers = new FormData(); fdServers.left = new FormAttachment( 0, Const.MARGIN ); fdServers.top = new FormAttachment( 0, Const.MARGIN ); fdServers.right = new FormAttachment( 100, -Const.MARGIN ); fdServers.bottom = new FormAttachment( wTestCl, -Const.MARGIN ); wServers.setLayoutData( fdServers ); FormData fdServersComp = new FormData(); fdServersComp.left = new FormAttachment( 0, 0 ); fdServersComp.top = new FormAttachment( 0, 0 ); fdServersComp.right = new FormAttachment( 100, 0 ); fdServersComp.bottom = new FormAttachment( 100, 0 ); wServersComp.setLayoutData( fdServersComp ); wServersComp.layout(); wServersTab.setControl( wServersComp ); } private void addSettingsTab() { wSettingsTab = new CTabItem( wTabFolder, SWT.NONE ); wSettingsTab.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.SettingsTab.TabTitle" ) ); FormLayout serversLayout = new FormLayout(); serversLayout.marginWidth = Const.FORM_MARGIN; serversLayout.marginHeight = Const.FORM_MARGIN; Composite wSettingsComp = new Composite( wTabFolder, SWT.NONE ); wSettingsComp.setLayout( serversLayout ); props.setLook( wSettingsComp ); ColumnInfo[] columnsMeta = new ColumnInfo[2]; columnsMeta[0] = new ColumnInfo( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.SettingsTab.Property.Column" ), ColumnInfo.COLUMN_TYPE_TEXT, false ); columnsMeta[1] = new ColumnInfo( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.SettingsTab.Value.Column" ), ColumnInfo.COLUMN_TYPE_TEXT, false ); columnsMeta[1].setUsingVariables( true ); wSettings = new TableView( transMeta, wSettingsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, columnsMeta, 1, lsMod, props ); FormData fdServers = new FormData(); fdServers.left = new FormAttachment( 0, Const.MARGIN ); fdServers.top = new FormAttachment( 0, Const.MARGIN ); fdServers.right = new FormAttachment( 100, -Const.MARGIN ); fdServers.bottom = new FormAttachment( 100, -Const.MARGIN ); wSettings.setLayoutData( fdServers ); FormData fdServersComp = new FormData(); fdServersComp.left = new FormAttachment( 0, 0 ); fdServersComp.top = new FormAttachment( 0, 0 ); fdServersComp.right = new FormAttachment( 100, 0 ); fdServersComp.bottom = new FormAttachment( 100, 0 ); wSettingsComp.setLayoutData( fdServersComp ); wSettingsComp.layout(); wSettingsTab.setControl( wSettingsComp ); } private void addFieldsTab() { wFieldsTab = new CTabItem( wTabFolder, SWT.NONE ); wFieldsTab.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.FieldsTab.TabTitle" ) ); FormLayout fieldsLayout = new FormLayout(); fieldsLayout.marginWidth = Const.FORM_MARGIN; fieldsLayout.marginHeight = Const.FORM_MARGIN; Composite wFieldsComp = new Composite( wTabFolder, SWT.NONE ); wFieldsComp.setLayout( fieldsLayout ); props.setLook( wFieldsComp ); wGet = new Button( wFieldsComp, SWT.PUSH ); wGet.setText( BaseMessages.getString( PKG, "System.Button.GetFields" ) ); wGet.setToolTipText( BaseMessages.getString( PKG, "System.Tooltip.GetFields" ) ); lsGet = new Listener() { @Override public void handleEvent(Event e ) { getPreviousFields( wFields ); } }; wGet.addListener( SWT.Selection, lsGet ); setButtonPositions( new Button[]{wGet}, Const.MARGIN, null ); final int fieldsRowCount = model.getFields().size(); String[] names = this.fieldNames != null ? this.fieldNames : new String[]{""}; ColumnInfo[] columnsMeta = new ColumnInfo[2]; columnsMeta[0] = new ColumnInfo( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.NameColumn.Column" ), ColumnInfo.COLUMN_TYPE_CCOMBO, names, false ); columnsMeta[1] = new ColumnInfo( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TargetNameColumn.Column" ), ColumnInfo.COLUMN_TYPE_TEXT, false ); wFields = new TableView( transMeta, wFieldsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, columnsMeta, fieldsRowCount, lsMod, props ); FormData fdFields = new FormData(); fdFields.left = new FormAttachment( 0, Const.MARGIN ); fdFields.top = new FormAttachment( 0, Const.MARGIN ); fdFields.right = new FormAttachment( 100, -Const.MARGIN ); fdFields.bottom = new FormAttachment( wGet, -Const.MARGIN ); wFields.setLayoutData( fdFields ); FormData fdFieldsComp = new FormData(); fdFieldsComp.left = new FormAttachment( 0, 0 ); fdFieldsComp.top = new FormAttachment( 0, 0 ); fdFieldsComp.right = new FormAttachment( 100, 0 ); fdFieldsComp.bottom = new FormAttachment( 100, 0 ); wFieldsComp.setLayoutData( fdFieldsComp ); wFieldsComp.layout(); wFieldsTab.setControl( wFieldsComp ); } private void fillOptionsGroup( Composite parentTab ) { int margin = Const.MARGIN; wSettingsGroup = new Group( parentTab, SWT.SHADOW_NONE ); props.setLook( wSettingsGroup ); wSettingsGroup.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.SettingsGroup.Label" ) ); FormLayout settingGroupLayout = new FormLayout(); settingGroupLayout.marginWidth = 10; settingGroupLayout.marginHeight = 10; wSettingsGroup.setLayout( settingGroupLayout ); wTimeOut = new LabelTimeComposite( wSettingsGroup, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TimeOut" + ".Label" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TimeOut.Tooltip" ) ); props.setLook( wTimeOut ); wTimeOut.addModifyListener( lsMod ); wlBatchSize = new Label( wSettingsGroup, SWT.RIGHT ); wlBatchSize.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.BatchSize.Label" ) ); props.setLook( wlBatchSize ); wBatchSize = new TextVar( transMeta, wSettingsGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); props.setLook( wBatchSize ); wBatchSize.addModifyListener( lsMod ); wlStopOnError = new Label( wSettingsGroup, SWT.RIGHT ); wlStopOnError.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.StopOnError.Label" ) ); wStopOnError = new Button( wSettingsGroup, SWT.CHECK | SWT.RIGHT ); wStopOnError.setToolTipText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.StopOnError.Tooltip" ) ); wStopOnError.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0 ) { widgetSelected( arg0 ); } @Override public void widgetSelected(SelectionEvent arg0 ) { model.setChanged(); } } ); wIdInField = new LabelComboVar( transMeta, wSettingsGroup, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IdField.Label" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IdField.Tooltip" ) ); props.setLook( wIdInField ); wIdInField.getComboWidget().setEditable( true ); wIdInField.addModifyListener( lsMod ); wIdInField.addFocusListener( new FocusListener() { @Override public void focusLost(org.eclipse.swt.events.FocusEvent e ) { } @Override public void focusGained(org.eclipse.swt.events.FocusEvent e ) { getPreviousFields( wIdInField ); } } ); getPreviousFields( wIdInField ); wlIsOverwrite = new Label( wSettingsGroup, SWT.RIGHT ); wlIsOverwrite.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Overwrite.Label" ) ); wIsOverwrite = new Button( wSettingsGroup, SWT.CHECK | SWT.RIGHT ); wIsOverwrite.setToolTipText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Overwrite.Tooltip" ) ); wIsOverwrite.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0 ) { widgetSelected( arg0 ); }
@Override public void widgetSelected(SelectionEvent arg0 ) { model.setChanged(); } } ); wlUseOutput = new Label( wSettingsGroup, SWT.RIGHT ); wlUseOutput.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.UseOutput.Label" ) ); wUseOutput = new Button( wSettingsGroup, SWT.CHECK | SWT.RIGHT ); wUseOutput.setToolTipText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.UseOutput.Tooltip" ) ); wUseOutput.addSelectionListener( new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0 ) { widgetSelected( arg0 ); } @Override public void widgetSelected(SelectionEvent arg0 ) { wIdOutField.setEnabled( wUseOutput.getSelection() ); model.setChanged(); } } ); wIdOutField = new LabelTextVar( transMeta, wSettingsGroup, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IdOutField.Label" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IdOutField.Tooltip" ) ); props.setLook( wIdOutField ); wIdOutField.setEnabled( wUseOutput.getSelection() ); wIdOutField.addModifyListener( lsMod ); wlIsJson = new Label( wSettingsGroup, SWT.RIGHT ); wlIsJson.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IsJson.Label" ) ); wIsJson = new Button( wSettingsGroup, SWT.CHECK | SWT.RIGHT ); wIsJson.setToolTipText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.IsJson.Tooltip" ) ); wIsJson.addSelectionListener( new SelectionListener() {
@Override public void widgetDefaultSelected(SelectionEvent arg0 ) { widgetSelected( arg0 ); } @Override public void widgetSelected(SelectionEvent arg0 ) { wJsonField.setEnabled( wIsJson.getSelection() ); wFields.setEnabled( !wIsJson.getSelection() ); wFields.setVisible( !wIsJson.getSelection() ); wGet.setEnabled( !wIsJson.getSelection() ); model.setChanged(); } } ); wJsonField = new LabelComboVar( transMeta, wSettingsGroup, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.JsonField.Label" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.JsonField.Tooltip" ) ); wJsonField.getComboWidget().setEditable( true ); props.setLook( wJsonField ); wJsonField.addModifyListener( lsMod ); wJsonField.addFocusListener( new FocusListener() { @Override public void focusLost(org.eclipse.swt.events.FocusEvent e ) { } @Override public void focusGained(org.eclipse.swt.events.FocusEvent e ) { getPreviousFields( wJsonField ); } } ); getPreviousFields( wJsonField ); wJsonField.setEnabled( wIsJson.getSelection() ); Control[] settingsControls = new Control[]{wlBatchSize, wBatchSize, wlStopOnError, wStopOnError, wTimeOut, wIdInField, wlIsOverwrite, wIsOverwrite, wlUseOutput, wUseOutput, wIdOutField, wlIsJson, wIsJson, wJsonField}; placeControls( wSettingsGroup, settingsControls ); fdSettingsGroup = new FormData(); fdSettingsGroup.left = new FormAttachment( 0, margin ); fdSettingsGroup.top = new FormAttachment( wIndexGroup, margin ); fdSettingsGroup.right = new FormAttachment( 100, -margin ); wSettingsGroup.setLayoutData( fdSettingsGroup ); } private void getPreviousFields( LabelComboVar combo ) { String value = combo.getText(); combo.removeAll(); combo.setItems( getInputFieldNames() ); if ( value != null ) { combo.setText( value ); } } private String[] getInputFieldNames() { if ( this.fieldNames == null ) { try { RowMetaInterface r = transMeta.getPrevStepFields( stepname ); if ( r != null ) { fieldNames = r.getFieldNames(); } } catch ( KettleException ke ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.FailedToGetFields.DialogTitle" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.FailedToGetFields.DialogMessage" ), ke ); return new String[0]; } } return fieldNames; } private void getPreviousFields( TableView table ) { try { RowMetaInterface r = transMeta.getPrevStepFields( stepname ); if ( r != null ) { BaseStepDialog.getFieldsFromPrevious( r, table, 1, new int[]{1, 2}, null, 0, 0, null ); } } catch ( KettleException ke ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.GetFieldsFailed.Title" ), BaseMessages .getString( PKG, "System.Dialog.GetFieldsFailed.Message" ), ke ); } } private void placeControls( Group group, Control[] controls ) { Control previousAbove = group; Control previousLeft = group; for ( Control control : controls ) { if ( control instanceof Label ) { addLabelAfter( control, previousAbove ); previousLeft = control; } else { addWidgetAfter( control, previousAbove, previousLeft ); previousAbove = control; previousLeft = group; } } } private void addWidgetAfter( Control widget, Control widgetAbove, Control widgetLeft ) { props.setLook( widget ); FormData fData = new FormData(); fData.left = new FormAttachment( widgetLeft, Const.MARGIN ); fData.top = new FormAttachment( widgetAbove, Const.MARGIN ); fData.right = new FormAttachment( 100, -Const.MARGIN ); widget.setLayoutData( fData ); } private void addLabelAfter( Control widget, Control widgetAbove ) { props.setLook( widget ); FormData fData = new FormData(); fData.top = new FormAttachment( widgetAbove, Const.MARGIN ); fData.right = new FormAttachment( Const.MIDDLE_PCT, -Const.MARGIN ); widget.setLayoutData( fData ); }
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(), "" ) ); wJsonField.setEnabled( wIsJson.getSelection() ); wUseOutput.setSelection( in.isUseOutput() ); wIdOutField.setText( Const.NVL( in.getIdOutField(), "" ) ); wIdOutField.setEnabled( wUseOutput.getSelection() ); mapToTableView( model.getFieldsMap(), wFields ); for ( ElasticSearchBulkMeta.Server server : model.getServers() ) { wServers.add( server.address, "" + server.port ); } wServers.removeEmptyRows(); wServers.setRowNums(); mapToTableView( model.getSettingsMap(), wSettings ); wStepname.selectAll(); wStepname.setFocus(); } private void mapToTableView( Map<String, String> map, TableView table ) { for ( String key : map.keySet() ) { table.add( key, map.get( key ) ); } table.removeEmptyRows(); table.setRowNums(); } private void cancel() { stepname = null; model.setChanged( changed ); dispose(); } private void ok() { try { toModel( model ); } catch ( KettleException e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "ElasticSearchBulkDialog.ErrorValidateData.DialogTitle" ), BaseMessages.getString( PKG, "ElasticSearchBulkDialog.ErrorValidateData.DialogMessage" ), e ); } dispose(); } private void toModel( ElasticSearchBulkMeta in ) throws KettleException { stepname = wStepname.getText(); in.setType( wType.getText() ); in.setIndex( wIndex.getText() ); in.setBatchSize( wBatchSize.getText() ); in.setTimeOut( Const.NVL( wTimeOut.getText(), null ) ); in.setTimeoutUnit( wTimeOut.getTimeUnit() ); in.setIdInField( wIdInField.getText() ); in.setOverWriteIfSameId( StringUtils.isNotBlank( wIdInField.getText() ) && wIsOverwrite.getSelection() ); in.setStopOnError( wStopOnError.getSelection() ); in.setJsonInsert( wIsJson.getSelection() ); in.setJsonField( wIsJson.getSelection() ? wJsonField.getText() : null ); in.setIdOutField( wIdOutField.getText() ); in.setUseOutput( wUseOutput.getSelection() ); in.clearFields(); if ( !wIsJson.getSelection() ) { for ( int i = 0; i < wFields.getItemCount(); i++ ) { String[] row = wFields.getItem( i ); if ( StringUtils.isNotBlank( row[0] ) ) { in.addField( row[0], row[1] ); } } } in.clearServers(); for ( int i = 0; i < wServers.getItemCount(); i++ ) { String[] row = wServers.getItem( i ); if ( StringUtils.isNotBlank( row[0] ) ) { try { in.addServer( row[0], Integer.parseInt( row[1] ) ); } catch ( NumberFormatException nfe ) { in.addServer( row[0], ElasticSearchBulkMeta.DEFAULT_PORT ); } } } in.clearSettings(); for ( int i = 0; i < wSettings.getItemCount(); i++ ) { String[] row = wSettings.getItem( i ); in.addSetting( row[0], row[1] ); } } private enum TestType { INDEX, CLUSTER, } 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() ) ) ); RestHighLevelClient rclient=null;
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settingsBuilder.get("es.user"), settingsBuilder.get("es.password"))); for ( Server server : tempMeta.getServers() ) { rclient = new RestHighLevelClient(RestClient.builder( new HttpHost(server.getAddress(), Integer.valueOf(server .getPort()), settingsBuilder.get("es.schema"))).setHttpClientConfigCallback( new RestClientBuilder.HttpClientConfigCallback() { @Override public HttpAsyncClientBuilder customizeHttpClient( HttpAsyncClientBuilder httpClientBuilder) { return httpClientBuilder .setDefaultCredentialsProvider(credentialsProvider); } })); }
String[] index = tempMeta.getIndex().split(","); GetIndexRequest request = new GetIndexRequest(); request.indices(index); request.local(false); request.humanReadable(true); boolean exists = rclient.indices().exists(request, RequestOptions.DEFAULT); switch ( testType ) { case INDEX: if ( StringUtils.isBlank( tempMeta.getIndex() ) ) { showError( BaseMessages.getString( PKG, "ElasticSearchBulk.Error.NoIndex" ) ); break; }
if ( !exists ) { showError( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Error.NoIndex" ) ); return; }
showMessage( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestIndex.TestOK", "true" ) ); break; case CLUSTER:
MainResponse response = rclient.info(RequestOptions.DEFAULT); showMessage( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.TestCluster.TestOK", response.getClusterName(), response.getVersion() ) ); break; default: break; } }else{ showError( "Servers is null" ); } } catch ( NoNodeAvailableException | MasterNotDiscoveredException e ) { showError( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Error.NoNodesFound" ) ); } catch ( Exception e ) { showError( e.getLocalizedMessage() ); } } private void showError( String message ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR ); mb.setMessage( message ); mb.setText( BaseMessages.getString( PKG, "System.Dialog.Error.Title" ) ); mb.open(); } private void showMessage( String message ) { MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_INFORMATION ); mb.setMessage( message ); mb.setText( BaseMessages.getString( PKG, "ElasticSearchBulkDialog.Test.TestOKTitle" ) ); mb.open(); } @Override public String toString() { return this.getClass().getName(); } }
|