Examples of MJob


Examples of org.apache.sqoop.model.MJob

                           getFramework().getConnectionForms()
    );
  }

  public static MJob getJob(String name, MJob.Type type) {
    return new MJob(1, 1,
                    type,
                    getConnector(name).getJobForms(type),
                    getFramework().getJobForms(type)
    );
  }
View Full Code Here

Examples of org.apache.sqoop.model.MJob

*
*/
public class TestJobBean {
  @Test
  public void testSerialization() throws ParseException {
    MJob job = getJob("ahoj", MJob.Type.IMPORT);
    job.setName("The big job");
    job.setPersistenceId(666);

    // Fill some data at the beginning
    MStringInput input = (MStringInput) job.getConnectorPart().getForms()
      .get(0).getInputs().get(0);
    input.setValue("Hi there!");

    // Serialize it to JSON object
    JobBean bean = new JobBean(job);
    JSONObject json = bean.extract();

    // "Move" it across network in text form
    String string = json.toJSONString();

    // Retrieved transferred object
    JSONObject retrievedJson = (JSONObject)JSONValue.parseWithException(string);
    JobBean retrievedBean = new JobBean();
    retrievedBean.restore(retrievedJson);
    MJob target = retrievedBean.getJobs().get(0);

    // Check id and name
    assertEquals(666, target.getPersistenceId());
    assertEquals(MJob.Type.IMPORT, target.getType());
    assertEquals("The big job", target.getName());

    // Test that value was correctly moved
    MStringInput targetInput = (MStringInput) target.getConnectorPart()
      .getForms().get(0).getInputs().get(0);
    assertEquals("Hi there!", targetInput.getValue());
  }
View Full Code Here

Examples of org.apache.sqoop.model.MJob

    }

    // Load prepared connections into database
    loadJobs();

    MJob jobImport = handler.findJob(1, getDerbyConnection());
    assertNotNull(jobImport);
    assertEquals(1, jobImport.getPersistenceId());
    assertEquals("JA", jobImport.getName());
    assertEquals(MJob.Type.IMPORT, jobImport.getType());

    List<MForm> forms;

    // Check connector part
    forms = jobImport.getConnectorPart().getForms();
    assertEquals("Value5", forms.get(0).getInputs().get(0).getValue());
    assertNull(forms.get(0).getInputs().get(1).getValue());
    assertEquals("Value7", forms.get(1).getInputs().get(0).getValue());
    assertNull(forms.get(1).getInputs().get(1).getValue());

    // Check framework part
    forms = jobImport.getFrameworkPart().getForms();
    assertEquals("Value17", forms.get(0).getInputs().get(0).getValue());
    assertNull(forms.get(0).getInputs().get(1).getValue());
    assertEquals("Value19", forms.get(1).getInputs().get(0).getValue());
    assertNull(forms.get(1).getInputs().get(1).getValue());
  }
View Full Code Here

Examples of org.apache.sqoop.model.MJob

  }

  public static MSubmission submit(long jobId) {
    Repository repository = RepositoryManager.getRepository();

    MJob job = repository.findJob(jobId);
    if(job == null) {
      throw new SqoopException(FrameworkError.FRAMEWORK_0004,
        "Unknown job id " + jobId);
    }
    MConnection connection = repository.findConnection(job.getConnectionId());
    SqoopConnector connector =
      ConnectorManager.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(
      getConnectionConfigurationClass());
    FormUtils.fromForms(connection.getFrameworkPart().getForms(),
      frameworkConnection);

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

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

    // 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());
    }

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

    // Add job specific jars to
    request.addJars(initializer.getJars(request.getConnectorContext(),
      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 (submissionMutex) {
View Full Code Here

Examples of org.apache.sqoop.model.MJob

    assertTrue(handler.existsJob(4, getDerbyConnection()));
    assertFalse(handler.existsJob(5, getDerbyConnection()));
  }

  public void testCreateJob() throws Exception {
    MJob job = getJob();

    // Load some data
    fillJob(job);

    handler.createJob(job, getDerbyConnection());

    assertEquals(1, job.getPersistenceId());
    assertCountForTable("SQOOP.SQ_JOB", 1);
    assertCountForTable("SQOOP.SQ_JOB_INPUT", 4);

    MJob retrieved = handler.findJob(1, getDerbyConnection());
    assertEquals(1, retrieved.getPersistenceId());

    List<MForm> forms;
    forms = job.getConnectorPart().getForms();
    assertEquals("Value1", forms.get(0).getInputs().get(0).getValue());
    assertNull(forms.get(0).getInputs().get(1).getValue());
View Full Code Here

Examples of org.apache.sqoop.model.MJob

  }

  public void testUpdateJob() throws Exception {
    loadJobs();

    MJob job = handler.findJob(1, getDerbyConnection());

    List<MForm> forms;

    forms = job.getConnectorPart().getForms();
    ((MStringInput)forms.get(0).getInputs().get(1)).setValue("Injected");

    forms = job.getFrameworkPart().getForms();
    ((MStringInput)forms.get(1).getInputs().get(1)).setValue("Injected");

    job.setName("name");

    handler.updateJob(job, getDerbyConnection());

    assertEquals(1, job.getPersistenceId());
    assertCountForTable("SQOOP.SQ_JOB", 4);
    assertCountForTable("SQOOP.SQ_JOB_INPUT", 18);

    MJob retrieved = handler.findJob(1, getDerbyConnection());
    assertEquals("name", retrieved.getName());

    forms = retrieved.getConnectorPart().getForms();
    assertEquals("Injected", forms.get(0).getInputs().get(1).getValue());

    forms = retrieved.getFrameworkPart().getForms();
    assertEquals("Injected", forms.get(1).getInputs().get(1).getValue());
  }
View Full Code Here

Examples of org.apache.sqoop.model.MJob

      MJob.Type type = MJob.Type.valueOf(stringType);

      List<MForm> connectorForms = restoreForms(connectorPart);
      List<MForm> frameworkForms = restoreForms(frameworkPart);

      MJob job = new MJob(
        connectorId,
        connectionId,
        type,
        new MJobForms(type, connectorForms),
        new MJobForms(type, frameworkForms)
      );

      job.setPersistenceId((Long) object.get(ID));
      job.setName((String) object.get(NAME));

      jobs.add(job);
    }

    if(jsonObject.containsKey(CONNECTOR_RESOURCES)) {
View Full Code Here

Examples of org.apache.sqoop.model.MJob

    ConsoleReader reader = new ConsoleReader();

    JobBean jobBean = readJob(jobId);

    // TODO(jarcec): Check that we have expected data
    MJob job = jobBean.getJobs().get(0);
    ResourceBundle frameworkBundle
      = jobBean.getFrameworkBundle();
    ResourceBundle connectorBundle
      = jobBean.getConnectorBundle(job.getConnectorId());

    Status status = Status.FINE;

    io.out.println(getResource().getString(Constants.RES_PROMPT_UPDATE_JOB_METADATA));
View Full Code Here

Examples of org.apache.sqoop.model.MJob

    ConsoleReader reader = new ConsoleReader();

    JobBean jobBean = readJob(jobId);

    // TODO(jarcec): Check that we have expected data
    MJob job = jobBean.getJobs().get(0);
    ResourceBundle frameworkBundle
      = jobBean.getFrameworkBundle();
    ResourceBundle connectorBundle
      = jobBean.getConnectorBundle(job.getConnectorId());

    Status status = Status.FINE;

    // Remove persistent id as we're making a clone
    job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);

    io.out.println(getResource().getString(Constants
        .RES_PROMPT_UPDATE_JOB_METADATA));

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

      // Fill in data from user
      if(!fillJob(io, reader, job, connectorBundle, frameworkBundle)) {
        return;
      }

      // Try to create
      status = createJobApplyValidations(job);
    } while(!status.canProceed());

    io.out.println(MessageFormat.format(getResource()
        .getString(Constants.RES_CLONE_JOB_SUCCESSFUL), status.name(),
        job.getPersistenceId()));
  }
View Full Code Here

Examples of org.apache.sqoop.model.MJob

    MConnector connector = connectorBean.getConnectors().get(0);
    ResourceBundle connectorBundle = connectorBean.getResourceBundles().get(connector.getPersistenceId());

    MJob.Type jobType = MJob.Type.valueOf(type.toUpperCase());

    MJob job = new MJob(
      connector.getPersistenceId(),
      connection.getPersistenceId(),
      jobType,
      connector.getJobForms(jobType),
      framework.getJobForms(jobType)
    );

    Status status = Status.FINE;

    io.out.println(getResource().getString(Constants.RES_PROMPT_FILL_JOB_METADATA));

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

      // Fill in data from user
      if(!fillJob(io, reader, job, connectorBundle, frameworkBundle)) {
        return;
      }

      // Try to create
      status = createJobApplyValidations(job);
    } while(!status.canProceed());

    io.out.println(MessageFormat.format(getResource()
        .getString(Constants.RES_CREATE_JOB_SUCCESSFUL), status.name(),
        job.getPersistenceId()));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.