Package org.apache.sqoop.common

Examples of org.apache.sqoop.common.SqoopException


  public void deleteJob(final long id) {
    doWithConnection(new DoWithConnection() {
      @Override
      public Object doIt(Connection conn) {
        if(!handler.existsJob(id, conn)) {
          throw new SqoopException(RepositoryError.JDBCREPO_0020,
            "Invalid id: " + id);
        }
        if(handler.inUseJob(id, conn)) {
          throw new SqoopException(RepositoryError.JDBCREPO_0022,
            "Id in use: " + id);
        }

        handler.deleteJob(id, conn);
        return null;
View Full Code Here


  public void createSubmission(final MSubmission submission) {
    doWithConnection(new DoWithConnection() {
      @Override
      public Object doIt(Connection conn) {
        if(submission.hasPersistenceId()) {
          throw new SqoopException(RepositoryError.JDBCREPO_0023);
        }

        handler.createSubmission(submission, conn);
        return null;
      }
View Full Code Here

  public void updateSubmission(final MSubmission submission) {
    doWithConnection(new DoWithConnection() {
      @Override
      public Object doIt(Connection conn) {
       if(!submission.hasPersistenceId()) {
          throw new SqoopException(RepositoryError.JDBCREPO_0024);
        }
        if(!handler.existsSubmission(submission.getPersistenceId(), conn)) {
          throw new SqoopException(RepositoryError.JDBCREPO_0025,
            "Invalid id: " + submission.getPersistenceId());
        }

        handler.updateSubmission(submission, conn);
        return null;
View Full Code Here

      Constants.PRE_CLONE, Constants.SUF_INFO);
  }

  public Object executeCommand(List args) {
    if(!isInteractive()) {
      throw new SqoopException(ShellError.SHELL_0007, "clone");
    }

    if (args.size() == 0) {
      printlnResource(Constants.RES_CLONE_USAGE, getUsage());
      return null;
View Full Code Here

    } else {
      Long id = Long.parseLong(cid);

      // Check that user is not asking for non existing connector id
      if(!ConnectorManager.getInstance().getConnectorIds().contains(id)) {
        throw new SqoopException(ServerError.SERVER_0004, "Invalid id " + id);
      }

      connectors = new LinkedList<MConnector>();
      bundles = new HashMap<Long, ResourceBundle>();
View Full Code Here

  public List<MSubmission> findSubmissionsForJob(final long jobId) {
    return (List<MSubmission>) doWithConnection(new DoWithConnection() {
      @Override
      public Object doIt(Connection conn) throws Exception {
        if(!handler.existsJob(jobId, conn)) {
          throw new SqoopException(RepositoryError.JDBCREPO_0020,
            "Invalid id: " + jobId);
        }
        return handler.findSubmissionsForJob(jobId, conn);
      }
    });
View Full Code Here

  public MSubmission findSubmissionLastForJob(final long jobId) {
    return (MSubmission) doWithConnection(new DoWithConnection() {
      @Override
      public Object doIt(Connection conn) {
        if(!handler.existsJob(jobId, conn)) {
          throw new SqoopException(RepositoryError.JDBCREPO_0020,
            "Invalid id: " + jobId);
        }
        return handler.findSubmissionLastForJob(jobId, conn);
      }
    });
View Full Code Here

      context.getString(FrameworkConstants.SYSCFG_SUBMISSION_ENGINE);

    submissionEngine = (SubmissionEngine) ClassUtils
      .instantiate(submissionEngineClassName);
    if (submissionEngine == null) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0001,
        submissionEngineClassName);
    }

    submissionEngine.initialize(context,
      FrameworkConstants.PREFIX_SUBMISSION_ENGINE_CONFIG);

    // Execution engine
    String executionEngineClassName =
      context.getString(FrameworkConstants.SYSCFG_EXECUTION_ENGINE);

    executionEngine = (ExecutionEngine) ClassUtils
      .instantiate(executionEngineClassName);
    if (executionEngine == null) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0007,
        executionEngineClassName);
    }

    // We need to make sure that user has configured compatible combination of
    // submission engine and execution engine
    if (!submissionEngine
      .isExecutionEngineSupported(executionEngine.getClass())) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0008);
    }

    executionEngine.initialize(context,
      FrameworkConstants.PREFIX_EXECUTION_ENGINE_CONFIG);
View Full Code Here

    Repository repository = RepositoryManager.getInstance().getRepository();

    MJob job = repository.findJob(jobId);
    if (job == null) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0004,
        "Unknown job id " + jobId);
    }

    if (!job.getEnabled()) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0009,
        "Job id: " + job.getPersistenceId());
    }

    MConnection connection = repository.findConnection(job.getConnectionId());

    if (!connection.getEnabled()) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0010,
        "Connection id: " + connection.getPersistenceId());
    }

    SqoopConnector connector =
      ConnectorManager.getInstance().getConnector(job.getConnectorId());

    // Transform forms to connector specific classes
    Object connectorConnection = ClassUtils.instantiate(
      connector.getConnectionConfigurationClass());
    FormUtils.fromForms(connection.getConnectorPart().getForms(),
      connectorConnection);

    Object connectorJob = ClassUtils.instantiate(
      connector.getJobConfigurationClass(job.getType()));
    FormUtils.fromForms(job.getConnectorPart().getForms(), connectorJob);

    // Transform framework specific forms
    Object frameworkConnection = ClassUtils.instantiate(
      FrameworkManager.getInstance().getConnectionConfigurationClass());
    FormUtils.fromForms(connection.getFrameworkPart().getForms(),
      frameworkConnection);

    Object frameworkJob = ClassUtils.instantiate(
      FrameworkManager.getInstance().getJobConfigurationClass(job.getType()));
    FormUtils.fromForms(job.getFrameworkPart().getForms(), frameworkJob);

    // Create request object
    MSubmission summary = new MSubmission(jobId);
    SubmissionRequest request = executionEngine.createSubmissionRequest();

    summary.setCreationUser(username);
    summary.setLastUpdateUser(username);

    // Save important variables to the submission request
    request.setSummary(summary);
    request.setConnector(connector);
    request.setConfigConnectorConnection(connectorConnection);
    request.setConfigConnectorJob(connectorJob);
    request.setConfigFrameworkConnection(frameworkConnection);
    request.setConfigFrameworkJob(frameworkJob);
    request.setJobType(job.getType());
    request.setJobName(job.getName());
    request.setJobId(job.getPersistenceId());
    request.setNotificationUrl(notificationBaseUrl + jobId);

    // Let's register all important jars
    // sqoop-common
    request.addJarForClass(MapContext.class);
    // sqoop-core
    request.addJarForClass(FrameworkManager.class);
    // sqoop-spi
    request.addJarForClass(SqoopConnector.class);
    // Execution engine jar
    request.addJarForClass(executionEngine.getClass());
    // Connector in use
    request.addJarForClass(connector.getClass());

    // Extra libraries that Sqoop code requires
    request.addJarForClass(JSONValue.class);

    // Get connector callbacks
    switch (job.getType()) {
      case IMPORT:
        request.setConnectorCallbacks(connector.getImporter());
        break;
      case EXPORT:
        request.setConnectorCallbacks(connector.getExporter());
        break;
      default:
        throw new SqoopException(FrameworkError.FRAMEWORK_0005,
          "Unsupported job type " + job.getType().name());
    }
    LOG.debug("Using callbacks: " + request.getConnectorCallbacks());

    // Initialize submission from connector perspective
    CallbackBase baseCallbacks = request.getConnectorCallbacks();

    Class<? extends Initializer> initializerClass = baseCallbacks
      .getInitializer();
    Initializer initializer = (Initializer) ClassUtils
      .instantiate(initializerClass);

    if (initializer == null) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0006,
        "Can't create initializer instance: " + initializerClass.getName());
    }

    // Initializer context
    InitializerContext initializerContext = new InitializerContext(
      request.getConnectorContext());

    // Initialize submission from connector perspective
    initializer.initialize(initializerContext,
      request.getConfigConnectorConnection(),
      request.getConfigConnectorJob());

    // Add job specific jars to
    request.addJars(initializer.getJars(initializerContext,
      request.getConfigConnectorConnection(),
      request.getConfigConnectorJob()));

    // Retrieve and persist the schema
    request.getSummary().setConnectorSchema(initializer.getSchema(
      initializerContext,
      request.getConfigConnectorConnection(),
      request.getConfigConnectorJob()
      ));

    // Bootstrap job from framework perspective
    switch (job.getType()) {
      case IMPORT:
        prepareImportSubmission(request);
        break;
      case EXPORT:
        prepareExportSubmission(request);
        break;
      default:
        throw new SqoopException(FrameworkError.FRAMEWORK_0005,
          "Unsupported job type " + job.getType().name());
    }

    // Make sure that this job id is not currently running and submit the job
    // only if it's not.
    synchronized (getClass()) {
      MSubmission lastSubmission = repository.findSubmissionLastForJob(jobId);
      if (lastSubmission != null && lastSubmission.getStatus().isRunning()) {
        throw new SqoopException(FrameworkError.FRAMEWORK_0002,
          "Job with id " + jobId);
      }

      // TODO(jarcec): We might need to catch all exceptions here to ensure
      // that Destroyer will be executed in all cases.
View Full Code Here

    Class<? extends Destroyer> destroyerClass = baseCallbacks.getDestroyer();
    Destroyer destroyer = (Destroyer) ClassUtils.instantiate(destroyerClass);

    if (destroyer == null) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0006,
        "Can't create destroyer instance: " + destroyerClass.getName());
    }

    DestroyerContext destroyerContext = new DestroyerContext(
      request.getConnectorContext(), false, request.getSummary()
View Full Code Here

TOP

Related Classes of org.apache.sqoop.common.SqoopException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.