Ejemplo n.º 1
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.jface.action.Action#run()
   */
  @Override
  public void run() {
    // Make sure default teiid instance is connected
    if (!checkForConnectedServer()) return;

    ITeiidServer teiidServer = getServerManager().getDefaultServer();

    for (IFile nextVDB : this.selectedVDBs) {
      boolean doDeploy = VdbRequiresSaveChecker.insureOpenVdbSaved(nextVDB);
      if (doDeploy) {
        boolean deploySuccess = deployVdb(teiidServer, nextVDB);

        String vdbName = nextVDB.getFullPath().removeFileExtension().lastSegment();
        try {
          // make sure deployment worked before going on to the next one
          if (!teiidServer.hasVdb(vdbName)) {
            deploySuccess = false;
            break;
          }
        } catch (Exception ex) {
          DqpPlugin.Util.log(ex);
          Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
          String title =
              UTIL.getString(
                  I18N_PREFIX + "problemDeployingVdbDataSource.title",
                  vdbName,
                  teiidServer); //$NON-NLS-1$
          String message =
              UTIL.getString(
                  I18N_PREFIX + "problemDeployingVdbDataSource.msg",
                  vdbName,
                  teiidServer); //$NON-NLS-1$
          ErrorDialog.openError(
              shell, title, null, new Status(IStatus.ERROR, PLUGIN_ID, message, ex));
        }

        if (deploySuccess) {
          try {
            CreateVdbDataSourceAction.doCreateDataSource(vdbName, teiidServer);
          } catch (Exception ex) {
            Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
            MessageDialog.openError(
                shell,
                UTIL.getString("CreateVdbDataSourceAction.errorCreatingDataSourceForVDB", vdbName),
                ex.getMessage()); // $NON-NLS-1$
            DqpUiConstants.UTIL.log(
                IStatus.ERROR,
                ex,
                UTIL.getString(
                    "CreateVdbDataSourceAction.errorCreatingDataSourceForVDB",
                    vdbName)); //$NON-NLS-1$
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
 /*
  * Check that the default teiid instance is connected.  Show dialog if it is not.
  * @return 'true' if default teiid instance is connected, 'false' if not.
  */
 private boolean checkForConnectedServer() {
   ITeiidServer teiidServer = getServerManager().getDefaultServer();
   if (teiidServer == null || !teiidServer.isConnected()) {
     Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
     String title = UTIL.getString("ActionRequiresServer.title"); // $NON-NLS-1$
     String msg = UTIL.getString("ActionRequiresServer.msg"); // $NON-NLS-1$
     MessageDialog.openInformation(shell, title, msg);
     return false;
   }
   return true;
 }
Ejemplo n.º 3
0
  /** Ask the user to select the vdb and deploy it */
  public void queryUserAndRun() {
    // Make sure default teiid instance is connected
    if (!checkForConnectedServer()) return;

    ITeiidServer teiidServer = getServerManager().getDefaultServer();

    DeployVdbDialog dialog =
        new DeployVdbDialog(
            DqpUiPlugin.getDefault().getCurrentWorkbenchWindow().getShell(), designerProperties);

    dialog.open();

    if (dialog.getReturnCode() == Window.OK) {
      IFile vdb = dialog.getSelectedVdb();
      boolean doCreateDS = dialog.doCreateVdbDataSource();
      String jndiName = dialog.getVdbDataSourceJndiName();
      if (vdb != null) {
        boolean doDeploy = VdbRequiresSaveChecker.insureOpenVdbSaved(vdb);
        if (doDeploy) {
          deployVdb(teiidServer, vdb, true);
        }

        String vdbName = vdb.getFullPath().removeFileExtension().lastSegment();
        try {
          if (teiidServer.hasVdb(vdbName) && doCreateDS) {
            createVdbDataSource(vdb, jndiName, jndiName);
          }
        } catch (Exception ex) {
          DqpPlugin.Util.log(ex);
          Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
          String title =
              UTIL.getString(
                  I18N_PREFIX + "problemDeployingVdbDataSource.title",
                  vdbName,
                  teiidServer); //$NON-NLS-1$
          String message =
              UTIL.getString(
                  I18N_PREFIX + "problemDeployingVdbDataSource.msg",
                  vdbName,
                  teiidServer); //$NON-NLS-1$
          ErrorDialog.openError(
              shell, title, null, new Status(IStatus.ERROR, PLUGIN_ID, message, ex));
        }
      }
    }
  }
 /**
  * Constructs a <code>ModelingResourceFilter</code> that uses the existing resource filter
  * settings.
  *
  * @since 5.0.2
  */
 public ModelingResourceFilter() {
   addFilter(UiUtil.getResourceFilter(VIEW));
   setShowHiddenProjects(false);
 }
Ejemplo n.º 5
0
  /**
   * Deploy the given vdb to the given Teiid Instance
   *
   * @param teiidServer the Teiid Instance
   * @param vdbOrVdbFile the VDB
   * @param doCreateDataSource 'true' to create corresponding datasource, 'false' if not.
   */
  public static boolean deployVdb(
      ITeiidServer teiidServer, final Object vdbOrVdbFile, final boolean doCreateDataSource) {
    Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();

    try {
      if (!(vdbOrVdbFile instanceof IFile) && !(vdbOrVdbFile instanceof Vdb)) {
        throw new IllegalArgumentException(
            UTIL.getString(I18N_PREFIX + "selectionIsNotAVdb")); // $NON-NLS-1$
      }

      // make sure there is a Teiid connection
      if (!teiidServer.isConnected()) {
        return false;
      }

      Vdb vdb =
          ((vdbOrVdbFile instanceof IFile)
              ? new Vdb((IFile) vdbOrVdbFile, null)
              : (Vdb) vdbOrVdbFile);

      if (!vdb.isSynchronized()) {
        String title = UTIL.getString("VdbNotSyncdDialog.title"); // $NON-NLS-1$
        String msg = UTIL.getString("VdbNotSyncdDialog.msg"); // $NON-NLS-1$
        if (!MessageDialog.openQuestion(shell, title, msg)) return false;
      }

      final VdbDeployer deployer = new VdbDeployer(shell, vdb, teiidServer, doCreateDataSource);
      ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);

      failedModelName = null;

      IRunnableWithProgress runnable =
          new IRunnableWithProgress() {
            /**
             * {@inheritDoc}
             *
             * @see
             *     org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
             */
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
              try {
                failedModelName = deployer.deploy(monitor);
              } catch (Exception e) {
                throw new InvocationTargetException(e);
              }
            }
          };

      // deploy using progress monitor (UI is blocked)
      dialog.run(true, false, runnable);

      // process results
      VdbDeployer.DeployStatus status = deployer.getStatus();

      if (status.isError()) {
        String message = null;

        if (VdbDeployer.DeployStatus.CREATE_DATA_SOURCE_FAILED == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "createDataSourceFailed",
                  deployer.getVdbName(),
                  failedModelName); //$NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.DEPLOY_VDB_FAILED == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "vdbFailedToDeploy", deployer.getVdbName()); // $NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.TRANSLATOR_PROBLEM == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "translatorDoesNotExistOnServer",
                  deployer.getVdbName()); // $NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.SOURCE_CONNECTION_INFO_PROBLEM == status) {
          message =
              UTIL.getString(
                  I18N_PREFIX + "sourceMissingConnectionInfo",
                  deployer.getVdbName()); // $NON-NLS-1$
        } else if (VdbDeployer.DeployStatus.EXCEPTION == status) {
          throw deployer.getException(); // let catch block below
          // handle
        } else {
          // unexpected
          message =
              UTIL.getString(
                  I18N_PREFIX + "unknownDeployError", deployer.getVdbName(), status); // $NON-NLS-1$
        }

        // show user the error
        MessageDialog.openError(
            shell, UTIL.getString(I18N_PREFIX + "vdbNotDeployedTitle"), message); // $NON-NLS-1$
        return false;
      } else if (status.isDeployed()) {
        if (teiidServer.wasVdbRemoved(deployer.getVdbName())) {
          StringBuilder message =
              new StringBuilder(
                  UTIL.getString(
                      I18N_PREFIX + "vdbNotActiveMessage", // $NON-NLS-1$
                      vdb.getName()));

          for (String error : teiidServer.retrieveVdbValidityErrors(deployer.getVdbName())) {
            message.append(
                UTIL.getString(I18N_PREFIX + "notActiveErrorMessage", error)); // $NON-NLS-1$
          }

          MessageDialog.openWarning(
              shell,
              UTIL.getString(I18N_PREFIX + "vdbNotActiveTitle"),
              message.toString()); // $NON-NLS-1$
          return true;
        }
      } else {
        return false;
      }
    } catch (Throwable e) {
      if (e instanceof InvocationTargetException) {
        e = ((InvocationTargetException) e).getCause();
      }

      String vdbName = null;

      if (vdbOrVdbFile instanceof IFile) {
        vdbName = ((IFile) vdbOrVdbFile).getName();
      } else if (vdbOrVdbFile instanceof Vdb) {
        vdbName = ((Vdb) vdbOrVdbFile).getFile().getName();
      } else {
        vdbName = UTIL.getString(I18N_PREFIX + "selectionIsNotAVdb"); // $NON-NLS-1$
      }

      String message =
          UTIL.getString(
              I18N_PREFIX + "problemDeployingVdbToServer", vdbName, teiidServer); // $NON-NLS-1$
      UTIL.log(e);
      ErrorDialog.openError(shell, message, null, new Status(IStatus.ERROR, PLUGIN_ID, message, e));

      return false;
    }

    return true;
  }
  public static void executeAction(String id, Properties properties, boolean synchronous) {

    // IMPORT OPTIONS
    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_DDL)) {
      launchWizard(ImportMetadataAction.DDL_TO_RELATIONAL, properties, synchronous);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_FLAT_FILE)) {
      launchWizard(ImportMetadataAction.TEIID_FLAT_FILE, properties, synchronous);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_JDBC)) {
      launchWizard(ImportMetadataAction.JDBC, properties, synchronous);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_SALESFORCE)) {
      launchWizard(ImportMetadataAction.SALESFORCE_TO_RELATIONAL, properties, synchronous);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_XML_FILE)) {
      properties.put(IPropertiesContext.KEY_IMPORT_XML_TYPE, IPropertiesContext.IMPORT_XML_LOCAL);
      launchWizard(ImportMetadataAction.TEIID_XML_FILE, properties, synchronous);
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_XML_FILE_URL)) {
      properties.put(IPropertiesContext.KEY_IMPORT_XML_TYPE, IPropertiesContext.IMPORT_XML_REMOTE);
      launchWizard(ImportMetadataAction.TEIID_XML_FILE, properties, synchronous);
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_WSDL_TO_SOURCE)) {
      launchWizard(ImportMetadataAction.WSDL_TO_RELATIONAL, properties, synchronous);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.IMPORT_WSDL_TO_WS)) {
      launchWizard(ImportMetadataAction.WSDL_TO_WEB_SERVICE, properties, synchronous);
      return;
    }

    // NEW MODEL OPTIONS
    if (id.equalsIgnoreCase(COMMAND_IDS.NEW_MODEL_RELATIONAL_SOURCE)) {
      createNewModel(ModelType.PHYSICAL_LITERAL, MODEL_CLASSES.RELATIONAL, properties);
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.NEW_MODEL_RELATIONAL_VIEW)) {
      createNewModel(ModelType.VIRTUAL_LITERAL, MODEL_CLASSES.RELATIONAL, properties);
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.NEW_MODEL_WS)) {
      createNewModel(ModelType.VIRTUAL_LITERAL, MODEL_CLASSES.WEB_SERVICE, properties);
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.NEW_MODEL_XML_DOC)) {
      createNewModel(ModelType.VIRTUAL_LITERAL, MODEL_CLASSES.XML, properties);
      return;
    }

    // NEW OBJECT OPTIONS
    if (id.equalsIgnoreCase(COMMAND_IDS.DEFINE_VIEW_TABLE)) {
      DefineViewTableAction action = new DefineViewTableAction(properties);
      action.run();
      return;
    }

    // CONNECTIONPROFILE OPTIONS
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_JDBC)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_JDBC, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_FLAT_FILE)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_ODA_FLAT_FILE_ID, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_LDAP)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_LDAP_CONNECTION, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_MODESHAPE)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_MODESHAPE, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_SALESFORCE)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_SALESFORCE_CONNECTION, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_WEB_SERVICE)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_WS_CONNECTION, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_WEB_SERVICE_ODA)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_ODA_WS_ID, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_XML_FILE_LOCAL)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_XML_FILE_LOCAL, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_CONNECTION_XML_FILE_URL)) {
      createConnection(CONNECTION_PROFILE_IDS.CATEGORY_XML_FILE_URL, properties);
      return;
    }
    if (id.equalsIgnoreCase(COMMAND_IDS.GENERATE_WS_MODELS_FROM_WSDL)) {
      launchWizard(ImportMetadataAction.WSDL_TO_RELATIONAL, properties, synchronous);
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_VDB)) {
      ModelerUiViewUtils.launchWizard(
          "newVdbWizard", new StructuredSelection(), properties, synchronous); // $NON-NLS-1$
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.DEFINE_VDB)) {
      DefineVdbAction action = new DefineVdbAction(properties);
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.EDIT_VDB)) {
      EditVdbAction action = new EditVdbAction();
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.EXECUTE_VDB)) {
      ExecuteVdbAction action = new ExecuteVdbAction(properties);
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.DEPLOY_VDB)) {
      DeployVdbAction action = new DeployVdbAction(properties);
      action.queryUserAndRun();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.NEW_TEIID_MODEL_PROJECT)) {
      ModelerUiViewUtils.launchWizard(
          "newModelProject", new StructuredSelection(), properties, synchronous); // $NON-NLS-1$
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.DEFINE_TEIID_MODEL_PROJECT)) {
      DefineProjectAction action = new DefineProjectAction(properties);
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.OPEN_DATA_SOURCE_EXPLORER_VIEW)) {
      try {
        UiUtil.getWorkbenchPage()
            .showView(
                "org.eclipse.datatools.connectivity.DataSourceExplorerNavigator"); //$NON-NLS-1$
      } catch (final PartInitException err) {
        AdvisorUiConstants.UTIL.log(err);
        WidgetUtil.showError(err.getLocalizedMessage());
      }
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.PREVIEW_DATA)) {
      PreviewDataAction action = new PreviewDataAction(properties);
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.NEW_TEIID_SERVER)) {
      RuntimeAssistant.runNewServerAction(
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.EDIT_TEIID_SERVER)) {
      RuntimeAssistant.runEditServerAction(
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.CREATE_DATA_SOURCE)) {
      // make sure there is a Teiid connection
      if (RuntimeAssistant.ensureServerConnection(
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
          Messages.CreateDataSource_NoServerMessage)) {
        try {
          TeiidServer teiidServer = DqpPlugin.getInstance().getServerManager().getDefaultServer();

          CreateDataSourceAction action = new CreateDataSourceAction();
          action.setAdmin(teiidServer.getAdmin());

          action.setSelection(new StructuredSelection());

          action.setEnabled(true);
          action.run();
        } catch (Exception ex) {
          AdvisorUiConstants.UTIL.log(ex);
        }
      }

      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.DEFINE_SOURCE)) {
      DefineSourceAction action = new DefineSourceAction(properties);
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(COMMAND_IDS.GENERATE_REST_WAR)) {
      GenerateRESTWarAction action = new GenerateRESTWarAction(properties);
      action.run();
      return;
    }

    //		if( id.equalsIgnoreCase(COMMAND_IDS.GENERATE_SOAP_WAR)) {
    //			// TODO
    //	        return;
    //		}

    if (id.equalsIgnoreCase(COMMAND_IDS.DEPLOY_WAR)) {
      LaunchInstructionsAction action = new LaunchInstructionsAction(INSTRUCTIONS.DEPLOY_WAR_FILE);
      action.run();
      return;
    }

    if (id.equalsIgnoreCase(CHEAT_SHEET_IDS.CONSUME_SOAP_SERVICE)
        || id.equalsIgnoreCase(CHEAT_SHEET_IDS.CREATE_AND_TEST_VDB)
        || id.equalsIgnoreCase(CHEAT_SHEET_IDS.MODEL_FLAT_FILE_SOURCE)
        || id.equalsIgnoreCase(CHEAT_SHEET_IDS.MODEL_FROM_JDBC_SOURCE)
        || id.equalsIgnoreCase(CHEAT_SHEET_IDS.MODEL_XML_LOCAL_SOURCE)
        || id.equalsIgnoreCase(CHEAT_SHEET_IDS.MODEL_XML_REMOTE_SOURCE)
        || id.equalsIgnoreCase(CHEAT_SHEET_IDS.MULTI_SOURCE_VDB)) {
      executeCheatSheet(id);
      return;
    }

    MessageDialog.openWarning(
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
        "Unimplemented Action", //$NON-NLS-1$
        "Action for ID [" + id + "] is not yet implemented"); // $NON-NLS-1$ //$NON-NLS-2$
  }