Package azkaban.common.utils

Examples of azkaban.common.utils.Props


                                                       Props defaultProps,
                                                       Props overrides,
                                                       Map<File, File> pathOverrides,
                                                       ClassLoader parentClassLoader) {
        // first load additional props defined in this directory
        Props dirProps = loadLocalNonJobProps(currDir, defaultProps);

        // apply overrides
        dirProps = new Props(dirProps, overrides);

        ClassLoader loader = createClassLoaderForDir(parentClassLoader, currDir);

        // now load any files defined in this directory
        File[] status = currDir.listFiles();
        for(File f: status) {
            if(EXCLUDE_PATHS.contains(f.getName()) || f.getName().startsWith(".")) {
                // ignore common files
                continue;
            } else if(f.isFile() && f.getName().endsWith(JOB_SUFFIX)) {
                String name = f.getName().substring(0, f.getName().length() - JOB_SUFFIX.length());
                String jobPath = getJobPath(baseDir, currDir);
                if(jobs.containsKey(name))
                    throw new JobLoadException(
                            String.format(
                                    "Job at path [%s] has duplicate name[%s] as another job[%s].",
                                    jobPath,
                                    name,
                                    jobs.get(name)
                            )
                    );

                logger.debug("Loading job '" + name + "' with path " + jobPath);
                try {
                    Props jobProps = new Props(dirProps, f.getAbsolutePath());
                    jobs.put(name, new JobDescriptor(name, jobPath, f.getPath(), jobProps, loader));
                } catch(Exception e) {
                    throw new JobLoadException("Failed to create Job '" + name + "': "
                                               + e.getLocalizedMessage(), e);
                }
View Full Code Here


            throw new JobLoadException("Directory '" + dir + "' is not a valid directory path!");
        else if(!dir.canRead())
            throw new JobLoadException(dir + " is not a readable directory!");

        try {
            Props props = new Props(parent);
            for(File f: dir.listFiles()) {
                try {
                    String name = f.getName();
                    if(name.endsWith(".schema") || name.endsWith(".properties")) {
                        logger.debug("Loading properties from " + f.getAbsolutePath());
                        props.putLocal(new Props(null, f.getAbsolutePath()));
                    }
                } catch(UndefinedPropertyException e) {
                    throw new JobLoadException("Undefined property while loading properties in '"
                                               + f + "'.", e);
                }
View Full Code Here

                throw (RuntimeException) e;
            else
                throw new RuntimeException(e);
        } finally {
            long end = System.currentTimeMillis();
            Props props = new Props();
            props.put("start", Long.toString(start));
            props.put("end", Long.toString(end));
            props.put("succeeded", Boolean.toString(succeeded));
            props.put("jobNotStaleException", Boolean.toString(jobNotStaleException));
            try {
                props.storeLocal(new File(runLogDir, "run.properties"));
            } catch(IOException e) {
                _logger.warn(String.format("IOException when storing props to local dir[%s]",
                                           runLogDir), e);
                throw new RuntimeException(e);
            }
View Full Code Here

        }

        if(jobDirs.size() < 1)
            throw new IllegalArgumentException("No job directory given.");

        Props defaultProps = PropsUtils.loadPropsInDirs(_jobDirs, ".properties", ".schema");

        _baseClassLoader = getBaseClassloader();

        String defaultTimezoneID = defaultProps.getString(DEFAULT_TIMEZONE_ID, null);
        if (defaultTimezoneID != null) {
          DateTimeZone.setDefault(DateTimeZone.forID(defaultTimezoneID));
          TimeZone.setDefault(TimeZone.getTimeZone(defaultTimezoneID));
        }
       
        NamedPermitManager permitManager = getNamedPermitManager(defaultProps);
        JobWrappingFactory factory = new JobWrappingFactory(
                permitManager,
                new ReadWriteLockManager(),
                _logsDir.getAbsolutePath(),
                "java",
                new ImmutableMap.Builder<String, Class<? extends Job>>()
                 .put("java", JavaJob.class)
                 .put("command", ProcessJob.class)
                 .put("javaprocess", JavaProcessJob.class)
                 .put("pig", PigProcessJob.class)
                 .put("propertyPusher", NoopJob.class)
                 .put("python", PythonJob.class)
                 .put("ruby", RubyJob.class)
                 .put("script", ScriptJob.class).build());

        _hdfsUrl = defaultProps.getString("hdfs.instance.url", null);
        _jobManager = new JobManager(factory,
                                     _logsDir.getAbsolutePath(),
                                     defaultProps,
                                     _jobDirs,
                                     _baseClassLoader);

        _mailer = new Mailman(defaultProps.getString("mail.host", "localhost"),
                              defaultProps.getString("mail.user", ""),
                              defaultProps.getString("mail.password", ""));

        String failureEmail = defaultProps.getString("job.failure.email", null);
        String successEmail = defaultProps.getString("job.success.email", null);
        int schedulerThreads = defaultProps.getInt("scheduler.threads", 50);
        _instanceName = defaultProps.getString(INSTANCE_NAME, "");
       
        final File initialJobDir = _jobDirs.get(0);
        File schedule = getScheduleFile(defaultProps, initialJobDir);
        File backup = getBackupFile(defaultProps, initialJobDir);
        File executionsStorageDir = new File(
                defaultProps.getString("azkaban.executions.storage.dir", initialJobDir.getAbsolutePath() + "/executions")
        );
        if (! executionsStorageDir.exists()) executionsStorageDir.mkdirs();
        long lastExecutionId = getLastExecutionId(executionsStorageDir);
        logger.info(String.format("Using path[%s] for storing executions.", executionsStorageDir));
        logger.info(String.format("Last known execution id was [%s]", lastExecutionId));

        final ExecutableFlowSerializer flowSerializer = new DefaultExecutableFlowSerializer();
        final ExecutableFlowDeserializer flowDeserializer = new DefaultExecutableFlowDeserializer(_jobManager, factory);

        FlowExecutionSerializer flowExecutionSerializer = new FlowExecutionSerializer(flowSerializer);
        FlowExecutionDeserializer flowExecutionDeserializer = new FlowExecutionDeserializer(flowDeserializer);

        _allFlows = new CachingFlowManager(
                new RefreshableFlowManager(
                        _jobManager,
                        flowExecutionSerializer,
                        flowExecutionDeserializer,
                        executionsStorageDir,
                        lastExecutionId
                ),
                defaultProps.getInt("azkaban.flow.cache.size", 1000)
        );
        _jobManager.setFlowManager(_allFlows);

        _jobExecutorManager = new JobExecutorManager(
                    _allFlows,
                    _jobManager,
                    _mailer,
                    failureEmail,
                    successEmail,
                    schedulerThreads
                  );
       
        this._schedulerManager = new ScheduleManager(_jobExecutorManager, new LocalFileScheduleLoader(schedule, backup));

        /* set predefined log url prefix
        */
        String server_url = defaultProps.getString("server.url", null) ;
        if (server_url != null) {
            if (server_url.endsWith("/"))
              _jobExecutorManager.setRuntimeProperty(AppCommon.DEFAULT_LOG_URL_PREFIX, server_url + "logs?file=" );
            else
              _jobExecutorManager.setRuntimeProperty(AppCommon.DEFAULT_LOG_URL_PREFIX, server_url + "/logs?file=" );
View Full Code Here

     * @param suffixes File suffixes to load
     * @return The loaded set of schedules
     */
    public static Props loadPropsInDir(Props parent, File dir, String... suffixes) {
        try {
            Props props = new Props(parent);
            File[] files = dir.listFiles();
            if(files != null) {
                for(File f: files) {
                    if(f.isFile() && endsWith(f, suffixes)) {
                        props.putAll(new Props(null, f.getAbsolutePath()));
                    }
                }
            }
            return props;
        } catch(IOException e) {
View Full Code Here

     * @param dirs The directories to check for properties
     * @param suffixes The suffixes to load
     * @return The properties
     */
    public static Props loadPropsInDirs(List<File> dirs, String... suffixes) {
        Props props = new Props();
        for(File dir: dirs) {
            props.putLocal(loadPropsInDir(dir, suffixes));
        }
        return props;
    }
View Full Code Here

                if(files != null) {
                    for(File file: files)
                        loadPropsBySuffix(file, props, suffixes);
                }
            } else if(endsWith(jobPath, suffixes)) {
                props.putAll(new Props(null, jobPath.getAbsolutePath()));
            }
        } catch(IOException e) {
            throw new RuntimeException("Error loading schedule properties.", e);
        }
    }
View Full Code Here

    }

    private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{([a-zA-Z_.0-9]+)\\}");

    public static Props resolveProps(Props props) {
      Props resolvedProps = new Props();

      for(String key : props.getKeySet()) {
          StringBuffer replaced = new StringBuffer();
          String value = props.get(key);
          Matcher matcher = VARIABLE_PATTERN.matcher(value);
          while(matcher.find()) {
              String variableName = matcher.group(1);

              if (variableName.equals(key)) {
                  throw new IllegalArgumentException(
                          String.format("Circular property definition starting from property[%s]", key)
                  );
              }

              String replacement = props.get(variableName);
              if(replacement == null)
                  throw new UndefinedPropertyException("Could not find variable substitution for variable '"
                                                       + variableName + "' in key '" + key + "'.");

              replacement = replacement.replaceAll("\\\\", "\\\\\\\\");
              replacement = replacement.replaceAll("\\$", "\\\\\\$");

              matcher.appendReplacement(replaced, replacement);
              matcher.appendTail(replaced);

              value = replaced.toString();
              replaced = new StringBuffer();
              matcher = VARIABLE_PATTERN.matcher(value);
          }
          matcher.appendTail(replaced);
          resolvedProps.put(key, replaced.toString());
      }

      return resolvedProps;
    }
View Full Code Here

        // Maintain backwards compatibility, check if it's really a holder
        final Object type = descriptor.get("type");
        if (type != null && "FlowExecutionHolder".equals(type.toString())) {
            retVal = new FlowExecutionHolder(
                    flowDeserializer.apply(Verifier.getVerifiedObject(descriptor, "flow", Map.class)),
                    new Props(new Props(), Verifier.getVerifiedObject(descriptor, "parentProps", Map.class))
            );
        }
        else {
            retVal = new FlowExecutionHolder(
                    flowDeserializer.apply(descriptor),
                    new Props()
            );
        }

        return retVal;
    }
View Full Code Here

    public void testSanity() throws Throwable
    {
        final CountDownLatch completionLatch = new CountDownLatch(1);

        final Job mockJob = EasyMock.createMock(Job.class);
        final Props overrideProps = new Props();
        final IndividualJobExecutableFlow executableFlow = new IndividualJobExecutableFlow("blah", "blah", jobManager);

        EasyMock.expect(jobManager.loadJob("blah", overrideProps, true)).andReturn(mockJob).once();
        EasyMock.expect(mockJob.getId()).andReturn("success Job").once();

        mockJob.run();
        EasyMock.expectLastCall().andAnswer(new IAnswer<Void>()
        {
            @Override
            public Void answer() throws Throwable
            {
                Assert.assertEquals(Status.RUNNING, executableFlow.getStatus());

                return null;
            }
        }).once();

        final Props returnProps = new Props();
        EasyMock.expect(mockJob.getJobGeneratedProperties()).andReturn(returnProps).once();

        EasyMock.replay(mockJob, jobManager);

        Assert.assertEquals(Status.READY, executableFlow.getStatus());

        executableFlow.execute(
                overrideProps,
                new FlowCallback()
                {
                    @Override
                    public void progressMade()
                    {
                        assertionViolated.set(true);
                        reason = String.format("progressMade() shouldn't actually be called.");
                    }

                    @Override
                    public void completed(Status status)
                    {
                        completionLatch.countDown();
                        if (Status.SUCCEEDED != status) {
                            assertionViolated.set(true);
                            reason = String.format("In executableFlow Callback: status[%s] != Status.SUCCEEDED", status);
                        }
                    }
                });

        completionLatch.await(1000, TimeUnit.MILLISECONDS);
        Assert.assertEquals(Status.SUCCEEDED, executableFlow.getStatus());
        Assert.assertEquals(emptyExceptions, executableFlow.getExceptions());
        Assert.assertEquals(overrideProps, executableFlow.getParentProps());
        Assert.assertEquals(returnProps, executableFlow.getReturnProps());

        Props otherProps = new Props();
        otherProps.put("billy", "blank");

        boolean exceptionThrown = false;
        try {
            executableFlow.execute(
                    otherProps,
View Full Code Here

TOP

Related Classes of azkaban.common.utils.Props

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.