/** * Load props from a file. */ public Props(final Props parent, final File file) throws IOException { this(parent); setSource(file.getPath()); final InputStream input = new BufferedInputStream(new FileInputStream(file)); try { loadFrom(input); } catch (final IOException e) { throw e; } finally { input.close(); } }
public static Props fromHierarchicalMap(final Map<String, Object> propsMap) { if (propsMap == null) { return null; } final String source = (String) propsMap.get("source"); final Map<String, String> propsParams = (Map<String, String>) propsMap.get("props"); final Map<String, Object> parent = (Map<String, Object>) propsMap.get("parent"); final Props parentProps = fromHierarchicalMap(parent); final Props props = new Props(parentProps, propsParams); props.setSource(source); return props; }
@Override public List<Pair<String, Props>> handle(final ResultSet rs) throws SQLException { if (!rs.next()) { return Collections.emptyList(); } final List<Pair<String, Props>> properties = new ArrayList<>(); do { final String name = rs.getString(3); final int eventType = rs.getInt(5); final byte[] dataBytes = rs.getBytes(6); final EncodingType encType = EncodingType.fromInteger(eventType); String propertyString = null; try { if (encType == EncodingType.GZIP) { // Decompress the sucker. propertyString = GZIPUtils.unGzipString(dataBytes, "UTF-8"); } else { propertyString = new String(dataBytes, "UTF-8"); } final Props props = PropsUtils.fromJSONString(propertyString); props.setSource(name); properties.add(new Pair<>(name, props)); } catch (final IOException e) { throw new SQLException(e); } } while (rs.next()); return properties; } }
private Flow convertAzkabanFlowToFlow(final AzkabanFlow azkabanFlow, final String flowName, final File flowFile) { final Flow flow = new Flow(flowName); flow.setAzkabanFlowVersion(Constants.AZKABAN_FLOW_VERSION_2_0); final Props props = azkabanFlow.getProps(); FlowLoaderUtils.addEmailPropsToFlow(flow, props); props.setSource(flowFile.getName()); flow.addAllFlowProperties(ImmutableList.of(new FlowProps(props))); // Convert azkabanNodes to nodes inside the flow. azkabanFlow.getNodes().values().stream() .map(n -> convertAzkabanNodeToNode(n, flowName, flowFile, azkabanFlow)) .forEach(n -> flow.addNode(n)); // Add edges for the flow. buildFlowEdges(azkabanFlow, flowName); if (this.edgeMap.containsKey(flowName)) { flow.addAllEdges(this.edgeMap.get(flowName)); } // Todo jamiesjc: deprecate startNodes, endNodes and numLevels, and remove below method finally. // Blow method will construct startNodes, endNodes and numLevels for the flow. flow.initialize(); return flow; }
@Test public void testFetchProjectProperties() throws Exception { final Props props1 = new Props(); props1.setSource("source1"); props1.put("key1", "value1"); props1.put("key2", "value2"); final Props props2 = new Props(); props2.setSource("source2"); props2.put("keykey", "valuevalue1"); props2.put("keyaaa", "valueaaa"); final List<Props> list = Arrays.asList(props1, props2); createThreeProjects(); final Project project = this.loader.fetchProjectByName("mytestProject"); this.loader.uploadProjectProperties(project, list); final Map<String, Props> propsMap = this.loader .fetchProjectProperties(project.getId(), project.getVersion()); Assert.assertEquals(propsMap.get("source1").get("key2"), "value2"); Assert.assertEquals(propsMap.get("source2").get("keyaaa"), "valueaaa"); }
prop.setSource(jobName + Constants.JOB_OVERRIDE_SUFFIX); oldProps = this.projectLoader.fetchProjectProperty(project, prop.getSource());
@Test public void testUploadOrUpdateProjectProperty() throws Exception { final Props props = new Props(); props.setSource("source1"); props.put("key1", "value1"); props.put("key2", "value2"); createThreeProjects(); final Project project = this.loader.fetchProjectByName("mytestProject"); this.loader.uploadProjectProperty(project, props); final Props sameProps = this.loader.fetchProjectProperty(project, props.getSource()); Assert.assertEquals(sameProps.get("key1"), "value1"); Assert.assertEquals(sameProps.get("key2"), "value2"); props.put("key2", "value9"); this.loader.updateProjectProperty(project, props); final Props sameProps2 = this.loader.fetchProjectProperty(project, props.getSource()); Assert.assertEquals(sameProps2.get("key2"), "value9"); }
/** * Load props from a file. * * @param parent * @param file * @throws IOException */ public Props(Props parent, File file) throws IOException { this(parent); setSource(file.getPath()); InputStream input = new BufferedInputStream(new FileInputStream(file)); try { loadFrom(input); } catch (IOException e) { input.close(); throw e; } input.close(); }
/** * Load props from a file. * * @param parent the parent * @param file the file * @throws IOException the io exception */ public Props(final Props parent, final File file) throws IOException { this(parent); setSource(file.getPath()); final InputStream input = new BufferedInputStream(new FileInputStream(file)); try { loadFrom(input); } catch (final IOException e) { throw e; } finally { input.close(); } }
@SuppressWarnings("unchecked") public static Props fromHierarchicalMap(Map<String, Object> propsMap) { if (propsMap == null) { return null; } String source = (String)propsMap.get("source"); Map<String, String> propsParams = (Map<String,String>)propsMap.get("props"); Map<String,Object> parent = (Map<String,Object>)propsMap.get("parent"); Props parentProps = fromHierarchicalMap(parent); Props props = new Props(parentProps, propsParams); props.setSource(source); return props; }
/** * From hierarchical map props. * * @param propsMap the props map * @return the props */ public static Props fromHierarchicalMap(final Map<String, Object> propsMap) { if (propsMap == null) { return null; } final String source = (String) propsMap.get("source"); final Map<String, String> propsParams = (Map<String, String>) propsMap.get("props"); final Map<String, Object> parent = (Map<String, Object>) propsMap.get("parent"); final Props parentProps = fromHierarchicalMap(parent); final Props props = new Props(parentProps, propsParams); props.setSource(source); return props; }
props.setSource(name); properties.add(new Pair<String, Props>(name, props)); } catch (IOException e) {
@Override public List<Pair<String, Props>> handle(final ResultSet rs) throws SQLException { if (!rs.next()) { return Collections.emptyList(); } final List<Pair<String, Props>> properties = new ArrayList<>(); do { final String name = rs.getString(3); final int eventType = rs.getInt(5); final byte[] dataBytes = rs.getBytes(6); final EncodingType encType = EncodingType.fromInteger(eventType); String propertyString = null; try { if (encType == EncodingType.GZIP) { // Decompress the sucker. propertyString = GZIPUtils.unGzipString(dataBytes, "UTF-8"); } else { propertyString = new String(dataBytes, "UTF-8"); } final Props props = PropsUtils.fromJSONString(propertyString); props.setSource(name); properties.add(new Pair<>(name, props)); } catch (final IOException e) { throw new SQLException(e); } } while (rs.next()); return properties; } }
public void setJobOverrideProperty(Project project, Props prop, String jobName) throws ProjectManagerException { prop.setSource(jobName+".jor"); Props oldProps = projectLoader.fetchProjectProperty(project, prop.getSource()); if(oldProps == null) { projectLoader.uploadProjectProperty(project, prop); } else { projectLoader.updateProjectProperty(project, prop); } return; }
private Flow convertAzkabanFlowToFlow(final AzkabanFlow azkabanFlow, final String flowName, final File flowFile) { final Flow flow = new Flow(flowName); flow.setAzkabanFlowVersion(Constants.AZKABAN_FLOW_VERSION_2_0); final Props props = azkabanFlow.getProps(); FlowLoaderUtils.addEmailPropsToFlow(flow, props); props.setSource(flowFile.getName()); flow.addAllFlowProperties(ImmutableList.of(new FlowProps(props))); // Convert azkabanNodes to nodes inside the flow. azkabanFlow.getNodes().values().stream() .map(n -> convertAzkabanNodeToNode(n, flowName, flowFile, azkabanFlow)) .forEach(n -> flow.addNode(n)); // Add edges for the flow. buildFlowEdges(azkabanFlow, flowName); if (this.edgeMap.containsKey(flowName)) { flow.addAllEdges(this.edgeMap.get(flowName)); } // Todo jamiesjc: deprecate startNodes, endNodes and numLevels, and remove below method finally. // Blow method will construct startNodes, endNodes and numLevels for the flow. flow.initialize(); return flow; }
props.setSource(path.getPath());
prop.setSource(jobName + Constants.JOB_OVERRIDE_SUFFIX); oldProps = this.projectLoader.fetchProjectProperty(project, prop.getSource());