Search in sources :

Example 76 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project scheduling by ow2-proactive.

the class VFSZipper method unzip.

public static void unzip(InputStream is, FileObject file) throws IOException {
    Closer closer = Closer.create();
    closer.register(is);
    try {
        OutputStream os = file.getContent().getOutputStream();
        ZipOutputStream zos = new ZipOutputStream(os);
        closer.register(zos);
        ByteStreams.copy(is, zos);
    } catch (IOException ioe) {
        throw closer.rethrow(ioe);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 77 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project wikidata-query-rdf by wikimedia.

the class Update method main.

/**
 * Run updates configured from the command line.
 * @throws Exception on error
 */
public static void main(String[] args) throws Exception {
    Closer closer = Closer.create();
    try {
        Properties buildProps = loadBuildProperties();
        log.info("Starting Updater {} ({})", buildProps.getProperty("git.build.version", "UNKNOWN"), buildProps.getProperty("git.commit.id", "UNKNOWN"));
        Updater<? extends Change.Batch> updater = initialize(args, closer);
        run(updater);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) Change(org.wikidata.query.rdf.tool.change.Change) Properties(java.util.Properties)

Example 78 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project incubator-gobblin by apache.

the class Log4jConfigHelper method updateLog4jConfiguration.

/**
 * Update the log4j configuration.
 *
 * @param targetClass the target class used to get the original log4j configuration file as a resource
 * @param log4jFileName the custom log4j configuration properties file name
 * @throws IOException if there's something wrong with updating the log4j configuration
 */
public static void updateLog4jConfiguration(Class<?> targetClass, String log4jFileName) throws IOException {
    final Closer closer = Closer.create();
    try {
        final InputStream inputStream = closer.register(targetClass.getResourceAsStream("/" + log4jFileName));
        final Properties originalProperties = new Properties();
        originalProperties.load(inputStream);
        LogManager.resetConfiguration();
        PropertyConfigurator.configure(originalProperties);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) InputStream(java.io.InputStream) Properties(java.util.Properties)

Example 79 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project incubator-gobblin by apache.

the class GobblinClusterManagerTest method testSendShutdownRequest.

@Test
public void testSendShutdownRequest() throws Exception {
    Logger log = LoggerFactory.getLogger("testSendShutdownRequest");
    Closer closer = Closer.create();
    try {
        CuratorFramework curatorFramework = TestHelper.createZkClient(this.testingZKServer, closer);
        final GetInstanceMessageNumFunc getMessageNumFunc = new GetInstanceMessageNumFunc(GobblinClusterManagerTest.class.getSimpleName(), curatorFramework);
        AssertWithBackoff assertWithBackoff = AssertWithBackoff.create().logger(log).timeoutMs(30000);
        this.gobblinClusterManager.sendShutdownRequest();
        Assert.assertEquals(curatorFramework.checkExists().forPath(String.format("/%s/INSTANCES/%s/MESSAGES", GobblinClusterManagerTest.class.getSimpleName(), TestHelper.TEST_HELIX_INSTANCE_NAME)).getVersion(), 0);
        assertWithBackoff.assertEquals(getMessageNumFunc, 1, "1 message queued");
        // Give Helix sometime to handle the message
        assertWithBackoff.assertEquals(getMessageNumFunc, 0, "all messages processed");
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) AssertWithBackoff(org.apache.gobblin.testing.AssertWithBackoff) CuratorFramework(org.apache.curator.framework.CuratorFramework) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Example 80 with Closer

use of org.apache.flink.shaded.guava30.com.google.common.io.Closer in project incubator-gobblin by apache.

the class HelixRetriggeringJobCallable method runJobExecutionLauncher.

/**
 * <p> Launch a planning job. The actual job will be launched
 * on task driver instance, which will handle the early-stop case
 * by a single while-loop.
 *
 * @see {@link GobblinHelixJobTask#run()} for the task driver logic.
 */
private void runJobExecutionLauncher() throws JobException {
    long startTime = 0;
    String newPlanningId;
    Closer closer = Closer.create();
    try {
        HelixManager planningJobHelixManager = this.taskDriverHelixManager.orElse(this.jobHelixManager);
        planningJobHelixManager.connect();
        String builderStr = jobProps.getProperty(GobblinClusterConfigurationKeys.DISTRIBUTED_JOB_LAUNCHER_BUILDER, GobblinHelixDistributeJobExecutionLauncher.Builder.class.getName());
        // Check if any existing planning job is running
        Optional<String> planningJobIdFromStore = jobsMapping.getPlanningJobId(this.jobUri);
        boolean nonblocking = false;
        // start of critical section to check if a job with same job name is running
        Lock jobLock = locks.get(this.jobUri);
        jobLock.lock();
        try {
            if (planningJobIdFromStore.isPresent() && !canRun(planningJobIdFromStore.get(), planningJobHelixManager)) {
                planningJobLauncherMetrics.skippedPlanningJobs.mark();
                return;
            }
            log.info("Planning job for {} does not exist. First time run.", this.jobUri);
            GobblinHelixDistributeJobExecutionLauncher.Builder builder = GobblinConstructorUtils.<GobblinHelixDistributeJobExecutionLauncher.Builder>invokeLongestConstructor(new ClassAliasResolver(GobblinHelixDistributeJobExecutionLauncher.Builder.class).resolveClass(builderStr));
            // Make a separate copy because we could update some of attributes in job properties (like adding planning id).
            Properties jobPlanningProps = new Properties();
            jobPlanningProps.putAll(this.jobProps);
            // Inject planning id and start time
            newPlanningId = HelixJobsMapping.createPlanningJobId(jobPlanningProps);
            jobPlanningProps.setProperty(GobblinClusterConfigurationKeys.PLANNING_ID_KEY, newPlanningId);
            jobPlanningProps.setProperty(GobblinClusterConfigurationKeys.PLANNING_JOB_CREATE_TIME, String.valueOf(System.currentTimeMillis()));
            builder.setSysProps(this.sysProps);
            builder.setJobPlanningProps(jobPlanningProps);
            builder.setPlanningJobHelixManager(planningJobHelixManager);
            builder.setAppWorkDir(this.appWorkDir);
            builder.setJobsMapping(this.jobsMapping);
            builder.setPlanningJobLauncherMetrics(this.planningJobLauncherMetrics);
            builder.setHelixMetrics(this.helixMetrics);
            // if the distributed job launcher should wait for planning job completion
            Config combined = ConfigUtils.propertiesToConfig(jobPlanningProps).withFallback(ConfigUtils.propertiesToConfig(sysProps));
            nonblocking = ConfigUtils.getBoolean(combined, GobblinClusterConfigurationKeys.NON_BLOCKING_PLANNING_JOB_ENABLED, GobblinClusterConfigurationKeys.DEFAULT_NON_BLOCKING_PLANNING_JOB_ENABLED);
            log.info("Planning job {} started.", newPlanningId);
            GobblinHelixDistributeJobExecutionLauncher launcher = builder.build();
            closer.register(launcher);
            this.jobsMapping.setPlanningJobId(this.jobUri, newPlanningId);
            startTime = System.currentTimeMillis();
            this.currentJobMonitor = launcher.launchJob(null);
            // make sure the planning job is initialized (or visible) to other parallel running threads,
            // so that the same critical section check (querying Helix for job completeness)
            // can be applied.
            HelixUtils.waitJobInitialization(planningJobHelixManager, newPlanningId, newPlanningId);
        } finally {
            planningJobHelixManager.disconnect();
            // end of the critical section to check if a job with same job name is running
            jobLock.unlock();
        }
        // we can remove the job spec from the catalog because Helix will drive this job to the end.
        this.deleteJobSpec();
        // If we are using non-blocking mode, this get() only guarantees the planning job is submitted.
        // It doesn't guarantee the job will finish because internally we won't wait for Helix completion.
        this.currentJobMonitor.get();
        this.currentJobMonitor = null;
        if (nonblocking) {
            log.info("Planning job {} submitted successfully.", newPlanningId);
        } else {
            log.info("Planning job {} finished.", newPlanningId);
            this.planningJobLauncherMetrics.updateTimeForCompletedPlanningJobs(startTime);
        }
    } catch (Exception e) {
        if (startTime != 0) {
            this.planningJobLauncherMetrics.updateTimeForFailedPlanningJobs(startTime);
        }
        log.error("Failed to run planning job for {}", this.jobUri, e);
        throw new JobException("Failed to run planning job for " + this.jobUri, e);
    } finally {
        try {
            closer.close();
        } catch (IOException e) {
            throw new JobException("Cannot properly close planning job for " + this.jobUri, e);
        }
    }
}
Also used : Closer(com.google.common.io.Closer) HelixManager(org.apache.helix.HelixManager) Config(com.typesafe.config.Config) IOException(java.io.IOException) Properties(java.util.Properties) URISyntaxException(java.net.URISyntaxException) HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) JobException(org.apache.gobblin.runtime.JobException) Lock(java.util.concurrent.locks.Lock) JobException(org.apache.gobblin.runtime.JobException) ClassAliasResolver(org.apache.gobblin.util.ClassAliasResolver)

Aggregations

Closer (com.google.common.io.Closer)213 IOException (java.io.IOException)95 File (java.io.File)26 Test (org.testng.annotations.Test)21 Path (org.apache.hadoop.fs.Path)18 Test (org.junit.Test)18 Properties (java.util.Properties)16 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)16 FileOutputStream (java.io.FileOutputStream)15 ArrayList (java.util.ArrayList)15 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)13 FileInputStream (java.io.FileInputStream)12 InputStream (java.io.InputStream)12 OutputStream (java.io.OutputStream)12 Map (java.util.Map)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 DataInputStream (java.io.DataInputStream)10 UncheckedIOException (java.io.UncheckedIOException)10 Configuration (org.apache.hadoop.conf.Configuration)10 Text (org.apache.hadoop.io.Text)9