private Status cloneLink(String linkArg, List<String> args, boolean isInteractive)
      throws IOException {
    printlnResource(Constants.RES_CLONE_CLONING_LINK, linkArg);

    ConsoleReader reader = new ConsoleReader();

    MLink connection = client.getLink(linkArg);
    // Remove persistent id as we're making a clone
    connection.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);

    Status status = Status.OK;

    ResourceBundle linkConfigBundle = client.getConnectorConfigBundle(connection.getConnectorId());

    if (isInteractive) {
      printlnResource(Constants.RES_PROMPT_UPDATE_LINK_CONFIG);

      do {
        // Print error introduction if needed
        if (!status.canProceed()) {
          errorIntroduction();
        }

        // Fill in data from user
        if (!fillLinkWithBundle(reader, connection, linkConfigBundle)) {
          return null;
        }

        status = client.saveLink(connection);
      } while (!status.canProceed());
    } else {
      LinkDynamicConfigOptions options = new LinkDynamicConfigOptions();
      options.prepareOptions(connection);
      CommandLine line = ConfigOptions.parseOptions(options, 0, args, false);
      if (fillLink(line, connection)) {
        status = client.saveLink(connection);
        if (!status.canProceed()) {
          printLinkValidationMessages(connection);
          return null;
        }
      } else {
        printLinkValidationMessages(connection);
        return null;
      }
    }

    printlnResource(
        Constants.RES_CLONE_LINK_SUCCESSFUL, status.name(), connection.getPersistenceId());

    return status;
  }
  @Test
  public void testDisabledLink() {
    MLink testConnection = new MLink(123l, null);
    testConnection.setPersistenceId(1234);
    testConnection.setEnabled(false);
    SqoopException exception =
        new SqoopException(
            DriverError.DRIVER_0010, "Connection id: " + testConnection.getPersistenceId());

    MLink mConnectionSpy = org.mockito.Mockito.spy(testConnection);
    when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock);
    when(jdbcRepoMock.findLink(123l)).thenReturn(mConnectionSpy);
    try {
      jobManager.getLink(123l);
    } catch (SqoopException ex) {
      assertEquals(ex.getMessage(), exception.getMessage());
      verify(repositoryManagerMock, times(1)).getRepository();
      verify(jdbcRepoMock, times(1)).findLink(123l);
    }
  }
Esempio n. 3
0
 /**
  * Create link.
  *
  * <p>With asserts to make sure that it was created correctly.
  *
  * @param link
  */
 protected void saveLink(MLink link) {
   SqoopUtils.fillObjectName(link);
   assertEquals(getClient().saveLink(link), Status.OK);
   assertNotSame(link.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
 }