http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/response/lineage/VerticesResult.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/response/lineage/VerticesResult.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/response/lineage/VerticesResult.java deleted file mode 100644 index df0fd2a..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/response/lineage/VerticesResult.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.response.lineage; - -import java.util.ArrayList; -import java.util.List; - -/** Class for Lineage API result having vertices. */ -public class VerticesResult extends GraphResult { - private List<Vertex> results; - - public List<Vertex> getResults() { - return results; - } - - @Override - public String toString() { - return String.format("VerticesResult{totalSize=%d, results=%s}", totalSize, results); - } - - public List<Vertex> filterByType(Vertex.VERTEX_TYPE vertexType) { - return filterVerticesByType(vertexType, results); - } - - public List<Vertex> filterVerticesByType(Vertex.VERTEX_TYPE vertexType, - List<Vertex> vertexList) { - List<Vertex> result = new ArrayList<>(); - for (Vertex vertex : vertexList) { - if (vertex.getType() == vertexType) { - result.add(vertex); - } - } - return result; - } - - public List<Vertex> filterByName(String name) { - return filterVerticesByName(name, results); - } - - public List<Vertex> filterVerticesByName(String name, List<Vertex> vertexList) { - List<Vertex> result = new ArrayList<>(); - for (Vertex vertex : vertexList) { - if (vertex.getName().equals(name)) { - result.add(vertex); - } - } - return result; - } - -}
http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/Brother.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/Brother.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/Brother.java deleted file mode 100755 index 4330bff..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/Brother.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.supportClasses; - -import org.apache.falcon.entity.v0.EntityType; -import org.apache.falcon.regression.core.bundle.Bundle; -import org.apache.falcon.regression.core.helpers.ColoHelper; -import org.apache.falcon.regression.core.helpers.entity.AbstractEntityHelper; -import org.apache.falcon.regression.core.response.ServiceResponse; -import org.apache.falcon.regression.core.util.Util.URLS; -import org.testng.TestNGException; -import org.apache.log4j.Logger; - -/** Class for running a rest request in a parallel thread. */ -public class Brother extends Thread { - private String operation; - private String data; - private URLS url; - private ServiceResponse output; - private static final Logger LOGGER = Logger.getLogger(Brother.class); - - public ServiceResponse getOutput() { - return output; - } - - private AbstractEntityHelper entityManagerHelper; - - public Brother(String threadName, String operation, EntityType entityType, ThreadGroup tGroup, - Bundle b, ColoHelper p, URLS url) { - super(tGroup, threadName); - this.operation = operation; - switch (entityType) { - case PROCESS: - this.data = b.getProcessData(); - this.entityManagerHelper = p.getProcessHelper(); - break; - case CLUSTER: - this.entityManagerHelper = p.getClusterHelper(); - this.data = b.getClusters().get(0); - break; - case FEED: - this.entityManagerHelper = p.getFeedHelper(); - this.data = b.getDataSets().get(0); - break; - default: - LOGGER.error("Unexpected entityType=" + entityType); - } - this.url = url; - this.output = new ServiceResponse(); - } - - public void run() { - try { - sleep(50L); - } catch (Exception e) { - e.printStackTrace(); - throw new TestNGException(e.getMessage()); - } - LOGGER.info("Brother " + this.getName() + " will be executing " + operation); - try { - switch (url) { - case SUBMIT_URL: - output = entityManagerHelper.submitEntity(data); - break; - case GET_ENTITY_DEFINITION: - output = entityManagerHelper.getEntityDefinition(data); - break; - case DELETE_URL: - output = entityManagerHelper.delete(data); - break; - case SUSPEND_URL: - output = entityManagerHelper.suspend(data); - break; - case SCHEDULE_URL: - output = entityManagerHelper.schedule(data); - break; - case RESUME_URL: - output = entityManagerHelper.resume(data); - break; - case SUBMIT_AND_SCHEDULE_URL: - output = entityManagerHelper.submitAndSchedule(data); - break; - case STATUS_URL: - output = entityManagerHelper.getStatus(data); - break; - default: - LOGGER.error("Unexpected url: " + url); - break; - } - LOGGER.info("Brother " + getName() + "'s response to the " - + operation + " is: " + output); - } catch (Exception e) { - e.printStackTrace(); - } - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/ExecResult.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/ExecResult.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/ExecResult.java deleted file mode 100644 index 8ce7342..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/ExecResult.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.supportClasses; - -import org.apache.commons.exec.CommandLine; - -/** - * Class with result of command line execution. - */ -public final class ExecResult { - - private final int exitVal; - private final String output; - private final String error; - private final CommandLine commandLine; - - public ExecResult(CommandLine commandLine, final int exitVal, final String output, - final String error) { - this.exitVal = exitVal; - this.output = output; - this.error = error; - this.commandLine = commandLine; - } - - public int getExitVal() { - return exitVal; - } - - public boolean hasSuceeded() { - return exitVal == 0; - } - - public String getOutput() { - return output; - } - - public String getError() { - return error; - } - - public CommandLine getCommandLine() { - return commandLine; - } - - @Override - public String toString() { - return "ExecResult{" - + "exitVal=" + exitVal - + ", output='" + output + '\'' - + ", error='" + error + '\'' - + ", commandLine=" + commandLine - + '}'; - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/HadoopFileEditor.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/HadoopFileEditor.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/HadoopFileEditor.java deleted file mode 100644 index 5ea765a..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/HadoopFileEditor.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.supportClasses; - -import org.apache.commons.io.FileUtils; -import org.apache.falcon.regression.core.util.Util; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.log4j.Logger; - -import java.io.BufferedWriter; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** Class for simulating editing and restoring of a file in hdfs. */ -public class HadoopFileEditor { - private static final Logger LOGGER = Logger.getLogger(HadoopFileEditor.class); - private FileSystem fs; - private List<String> paths; - private List<String> files; - - public HadoopFileEditor(FileSystem fs) { - this.fs = fs; - paths = new ArrayList<>(); - files = new ArrayList<>(); - } - - /** - * Method to edit a file present on HDFS. Path is the location on HDFS, - * @param path path of the file to be edited - * @param putAfterString first instance of string after which the text is to be - * @param toBeInserted the text to be inserted - * @throws IOException - */ - public void edit(String path, String putAfterString, String toBeInserted) throws IOException { - paths.add(path); - String currentFile = Util.getFileNameFromPath(path); - files.add(currentFile); - FileUtils.deleteQuietly(new File(currentFile)); - FileUtils.deleteQuietly(new File("." + currentFile + ".crc")); - FileUtils.deleteQuietly(new File(currentFile + ".bck")); - FileUtils.deleteQuietly(new File("tmp")); - - Path file = new Path(path); - //check if currentFile exists or not - if (fs.exists(file)) { - fs.copyToLocalFile(file, new Path(currentFile)); - FileUtils.copyFile(new File(currentFile), new File(currentFile + ".bck")); - BufferedWriter bufWriter = new BufferedWriter(new FileWriter("tmp")); - BufferedReader br = new BufferedReader(new FileReader(currentFile)); - String line; - boolean isInserted = false; - while ((line = br.readLine()) != null) { - bufWriter.write(line); - bufWriter.write('\n'); - if (line.contains(putAfterString) && !isInserted) { - bufWriter.write(toBeInserted); - isInserted = true; - } - } - br.close(); - bufWriter.close(); - FileUtils.deleteQuietly(new File(currentFile)); - FileUtils.copyFile(new File("tmp"), new File(currentFile)); - FileUtils.deleteQuietly(new File("tmp")); - - fs.delete(file, false); - File crcFile = new File("." + currentFile + ".crc"); - if (crcFile.exists()) { - LOGGER.info("Result of delete on crcFile" + crcFile + " : " + crcFile.delete()); - } - fs.copyFromLocalFile(new Path(currentFile), file); - } else { - LOGGER.info("Nothing to do, " + currentFile + " does not exists"); - } - } - - /** - * Restore back the original file to HDFS that was edited by edit function. - * @throws IOException - */ - public void restore() throws IOException { - for (int i = 0; i < paths.size(); i++) { - fs.delete(new Path(paths.get(i)), false); - FileUtils.deleteQuietly(new File(files.get(i))); - FileUtils.copyFile(new File(files.get(i) + ".bck"), - new File(files.get(i))); - fs.copyFromLocalFile(new Path(files.get(i)), new Path(paths.get(i))); - FileUtils.deleteQuietly(new File(files.get(i))); - FileUtils.deleteQuietly(new File(files.get(i) + ".bck")); - } - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/JmsMessageConsumer.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/JmsMessageConsumer.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/JmsMessageConsumer.java deleted file mode 100644 index 5ce60cd..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/JmsMessageConsumer.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.supportClasses; - -import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.log4j.Logger; - -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.MapMessage; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.Session; -import java.util.ArrayList; -import java.util.List; - -/** Collects JMS messages in a separate thread. */ -public class JmsMessageConsumer extends Thread { - /*URL of the JMS server - brokerURL = "tcp://host:61616?daemon=true"; - ActiveMQConnection.DEFAULT_BROKER_URL; - Name of the queue we will receive messages from - String subject = "FALCON.TOPIC";*/ - - private static final Logger LOGGER = Logger.getLogger(JmsMessageConsumer.class); - private static final int MAX_MESSAGE_COUNT = 1000; - - private final String brokerURL; - private final String topicName; - private final List<MapMessage> receivedMessages; - - public List<MapMessage> getReceivedMessages() { - return receivedMessages; - } - - public JmsMessageConsumer(String topicName, String brokerURL) { - super(topicName); - this.topicName = topicName; - this.brokerURL = brokerURL; - receivedMessages = new ArrayList<>(); - setDaemon(true); - } - - @Override - public void run() { - try { - // Getting JMS connection from the server - Connection connection = new ActiveMQConnectionFactory(brokerURL).createConnection(); - connection.start(); - - // Creating session for sending messages - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Destination destination = session.createTopic(topicName); - MessageConsumer consumer = session.createConsumer(destination); - - try { - LOGGER.info("Starting to receive messages."); - int count = 0; - for (; count < MAX_MESSAGE_COUNT; ++count) { - Message message = consumer.receive(); //blocking call - if (message == null) { - LOGGER.info("Received empty message, count = " + count); - } else { - LOGGER.info("Received message, id = " + message.getJMSMessageID()); - receivedMessages.add((MapMessage) message); - } - } - if (count >= MAX_MESSAGE_COUNT) { - LOGGER.warn("Not reading more messages, already read " + count + " messages."); - } - } finally { - LOGGER.info("Stopping to receive messages."); - connection.close(); - } - } catch (Exception e) { - LOGGER.info("caught exception: " + ExceptionUtils.getStackTrace(e)); - } - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/NotifyingAssert.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/NotifyingAssert.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/NotifyingAssert.java deleted file mode 100644 index 52b4fd3..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/supportClasses/NotifyingAssert.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.supportClasses; - -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.log4j.Logger; -import org.testng.asserts.IAssert; -import org.testng.asserts.SoftAssert; -import org.testng.collections.Maps; - -import java.util.Map; - -/** - * NotifyingAssert: This is same as SoftAssert provided by TestNg. Additionally, it adds an option - * of printing stacktrace whenever test execution fails. - */ -public class NotifyingAssert extends SoftAssert { - private final boolean printFailures; - // LinkedHashMap to preserve the order - private Map<AssertionError, IAssert> mErrors = Maps.newLinkedHashMap(); - private static final Logger LOGGER = Logger.getLogger(NotifyingAssert.class); - - /** - * Same of SoftAssert - just adds an option for logging assertion failure stacktraces. - * @param logFailures - switches on printing of stacktrace in logs on failures. - */ - public NotifyingAssert(boolean logFailures) { - this.printFailures = logFailures; - } - - @Override - public void executeAssert(IAssert a) { - try { - a.doAssert(); - } catch(AssertionError ex) { - onAssertFailure(a, ex); - mErrors.put(ex, a); - if (printFailures) { - LOGGER.info("Assertion failed - exception : " + ex + "\n" - + ExceptionUtils.getStackTrace(ex)); - } - } - } - - public void assertAll() { - if (!mErrors.isEmpty()) { - StringBuilder sb = new StringBuilder("The following asserts failed:\n"); - boolean first = true; - for (Map.Entry<AssertionError, IAssert> ae : mErrors.entrySet()) { - if (first) { - first = false; - } else { - sb.append(", "); - } - sb.append(ae.getValue().getMessage()); - } - throw new AssertionError(sb.toString()); - } - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/AssertUtil.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/AssertUtil.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/AssertUtil.java deleted file mode 100644 index cb79e9c..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/AssertUtil.java +++ /dev/null @@ -1,519 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.falcon.entity.v0.EntityType; -import org.apache.falcon.regression.core.bundle.Bundle; -import org.apache.falcon.regression.core.enumsAndConstants.MerlinConstants; -import org.apache.falcon.regression.core.response.ServiceResponse; -import org.apache.falcon.regression.core.supportClasses.ExecResult; -import org.apache.falcon.resource.APIResult; -import org.apache.hadoop.fs.ContentSummary; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.log4j.Logger; -import org.apache.oozie.client.Job; -import org.apache.oozie.client.OozieClient; -import org.apache.oozie.client.OozieClientException; -import org.json.JSONArray; -import org.json.JSONObject; -import org.testng.Assert; - -import javax.xml.bind.JAXBException; -import java.io.IOException; -import java.util.Collection; -import java.util.List; - -/** - * Util methods for assert. - */ -public final class AssertUtil { - - private AssertUtil() { - throw new AssertionError("Instantiating utility class..."); - } - - private static final Logger LOGGER = Logger.getLogger(AssertUtil.class); - - /** - * Asserts correctness of CLI metrics for recipe based process or feed replication. - * @param execResult CLI metrics exec result to be checked - * @param entityName name of recipe process or replication feed - * @param instanceNum expected number of process/feed instances in metrics output - * @param withData is data expected to be replicated - * @throws Exception - */ - public static void assertCLIMetrics(ExecResult execResult, String entityName, int instanceNum, boolean withData) - throws Exception { - String output = execResult.getOutput(); - Assert.assertTrue(StringUtils.isNotBlank(output), "Exec result output is blank."); - JSONObject jsonObject = new JSONObject(output); - int totalSize = jsonObject.getInt("totalSize"); - Assert.assertEquals(totalSize, instanceNum); - JSONArray array = jsonObject.getJSONArray("results"); - for (int i = 0; i < array.length(); i++) { - String name = array.getJSONObject(i).getString("name"); - Assert.assertTrue(name.contains(entityName)); - int timeTaken = array.getJSONObject(i).getInt("TIMETAKEN"); - Assert.assertTrue(timeTaken > 0, "TIMETAKEN metric should be greater then zero."); - int bytescopied = array.getJSONObject(i).getInt("BYTESCOPIED"); - Assert.assertTrue(bytescopied >= 0, "BYTESCOPIED metric should be greater or equal to zero."); - int copy = array.getJSONObject(i).getInt("COPY"); - if (withData) { - Assert.assertTrue(copy > 0, "COPY metric should be greater then zero."); - } else { - Assert.assertEquals(copy, 0, "COPY metric should be equal to zero as data was absent."); - } - } - } - - /** - * Checks that any path in list doesn't contains a string. - * - * @param paths list of paths - * @param shouldNotBePresent string that shouldn't be present - */ - public static void failIfStringFoundInPath( - List<Path> paths, String... shouldNotBePresent) { - for (Path path : paths) { - for (String aShouldNotBePresent : shouldNotBePresent) { - if (path.toUri().toString().contains(aShouldNotBePresent)) { - Assert.fail("String " + aShouldNotBePresent + " was not expected in path " - + - path.toUri().toString()); - } - } - } - } - - /** - * Checks that two lists have same size. - * - * @param expected expected list - * @param actual actual list - */ - public static void checkForListSizes(List<?> expected, List<?> actual) { - if (expected.size() != actual.size()) { - LOGGER.info("expected = " + expected); - } - checkForListSize(actual, expected.size()); - } - - /** - * Checks that two lists have same size. - * - * @param elements list of elements - * @param expectedSize expected size of the list - */ - public static void checkForListSize(List<?> elements, int expectedSize) { - if (elements.size() != expectedSize) { - LOGGER.info("expectedSize = " + expectedSize); - LOGGER.info("elements.size() = " + elements.size()); - LOGGER.info("elements = " + elements); - } - Assert.assertEquals(elements.size(), expectedSize, - "Size of expected and actual list don't match."); - } - - /** - * Checks that two lists has expected diff element. - * - * @param initialState first list - * @param finalState second list - * @param filename expected diff element - * @param expectedDiff diff count (positive for new elements) - */ - public static void compareDataStoreStates(List<String> initialState, - List<String> finalState, String filename, - int expectedDiff) { - - if (expectedDiff > -1) { - finalState.removeAll(initialState); - Assert.assertEquals(finalState.size(), expectedDiff); - if (expectedDiff != 0) { - Assert.assertTrue(finalState.get(0).contains(filename)); - } - } else { - expectedDiff = expectedDiff * -1; - initialState.removeAll(finalState); - Assert.assertEquals(initialState.size(), expectedDiff); - if (expectedDiff != 0) { - Assert.assertTrue(initialState.get(0).contains(filename)); - } - } - - - } - - /** - * Checks that two lists has expected diff element. - * - * @param initialState first list - * @param finalState second list - * @param expectedDiff diff count (positive for new elements) - */ - public static void compareDataStoreStates(List<String> initialState, - List<String> finalState, int expectedDiff) { - - if (expectedDiff > -1) { - finalState.removeAll(initialState); - Assert.assertEquals(finalState.size(), expectedDiff); - - } else { - expectedDiff = expectedDiff * -1; - initialState.removeAll(finalState); - Assert.assertEquals(initialState.size(), expectedDiff); - - } - - - } - - /** - * Checks that ServiceResponse status is SUCCEEDED. - * - * @param response ServiceResponse - * @throws JAXBException - */ - public static void assertSucceeded(ServiceResponse response) throws JAXBException { - final APIResult apiResult = Util.parseResponse(response); - Assert.assertNotNull(apiResult.getMessage(), "Status message is null"); - Assert.assertEquals(apiResult.getStatus(), APIResult.Status.SUCCEEDED, - "Status should be SUCCEEDED. Message: " + apiResult.getMessage()); - Assert.assertEquals(response.getCode(), 200, - "Status code should be 200. Message: " + apiResult.getMessage()); - } - - /** - * Checks that ServiceResponse status is SUCCEEDED. - * - * @param response ServiceResponse - * @return if the response was a success or not - */ - public static boolean checkSucceeded(ServiceResponse response) { - final APIResult apiResult; - try { - apiResult = Util.parseResponse(response); - } catch (JAXBException e) { - return false; - } - return apiResult.getStatus() == APIResult.Status.SUCCEEDED - && response.getCode() == 200 - && apiResult.getMessage() != null; - } - - /** - * Checks that ProcessInstancesResult status is SUCCEEDED. - * - * @param response ProcessInstancesResult - */ - public static void assertSucceeded(APIResult response) { - Assert.assertNotNull(response.getMessage(), "Status message is null"); - Assert.assertEquals(response.getStatus(), APIResult.Status.SUCCEEDED, - "Status should be SUCCEEDED. Message: " + response.getMessage()); - } - - /** - * Checks that ServiceResponse status is status FAILED. - * - * @param response ServiceResponse - * @param message message for exception - * @throws JAXBException - */ - public static void assertFailed(final ServiceResponse response, final String message) - throws JAXBException { - assertFailedWithStatus(response, 400, message); - } - - /** - * Assert that command executed unsuccessfully. - * - * @param execResult ExecResult of the command execution - */ - public static void assertFailed(ExecResult execResult, String expectedMessage) { - Assert.assertFalse(execResult.hasSuceeded(), - "Unexpectedly succeeded execResult: " + execResult); - Assert.assertTrue((execResult.getError() + execResult.getOutput()).contains(expectedMessage), - "Expected error: " + expectedMessage + " in execResult: " + execResult); - } - - /** - * Checks that ServiceResponse status is status FAILED with some status code. - * - * @param response ServiceResponse - * @param statusCode expected status code - * @param message message for exception - * @throws JAXBException - */ - public static void assertFailedWithStatus(final ServiceResponse response, final int statusCode, - final String message) throws JAXBException { - Assert.assertNotEquals(response.getMessage(), "null", "response message should not be null"); - Assert.assertEquals(Util.parseResponse(response).getStatus(), - APIResult.Status.FAILED, message); - Assert.assertEquals(response.getCode(), statusCode, message); - Assert.assertNotNull(Util.parseResponse(response).getRequestId(), "RequestId is null"); - } - - /** - * Checks that ServiceResponse status is status PARTIAL. - * - * @param response ServiceResponse - * @throws JAXBException - */ - public static void assertPartial(ServiceResponse response) throws JAXBException { - Assert.assertEquals(Util.parseResponse(response).getStatus(), APIResult.Status.PARTIAL); - Assert.assertEquals(response.getCode(), 200); - Assert.assertNotNull(Util.parseResponse(response).getMessage()); - } - - /** - * Checks that ServiceResponse status is status FAILED with status code 400. - * - * @param response ServiceResponse - * @throws JAXBException - */ - public static void assertFailed(ServiceResponse response) throws JAXBException { - Assert.assertNotEquals(response.getMessage(), "null", - "response message should not be null"); - - Assert.assertEquals(Util.parseResponse(response).getStatus(), APIResult.Status.FAILED); - Assert.assertEquals(response.getCode(), 400); - } - - /** - * Checks that ServiceResponse status is status FAILED with expectedMessage. - * - * @param response ServiceResponse - * @param expectedMessage expected message - * @throws JAXBException - */ - public static void assertFailedWithMessage(ServiceResponse response, String expectedMessage) throws JAXBException { - assertFailed(response); - Assert.assertTrue(response.getMessage().contains(expectedMessage), "Incorrect message in response"); - } - - /** - * Checks that Instance/Triage result status is FAILED. - * - * @param response APIResult response - */ - public static void assertFailed(APIResult response) { - Assert.assertNotEquals(response.getMessage(), "null", - "response message should not be null"); - Assert.assertEquals(response.getStatus(), APIResult.Status.FAILED, - "Status should be FAILED. Message: " + response.getMessage()); - } - - /** - * Checks that ServiceResponse status is status FAILED with status code 403. - * - * @param response ServiceResponse - * @throws JAXBException - */ - public static void assertFailedWith403(ServiceResponse response) throws JAXBException { - Assert.assertNotEquals(response.getMessage(), "null", "response message should not be null"); - - Assert.assertEquals(Util.parseResponse(response).getStatus(), APIResult.Status.FAILED); - Assert.assertEquals(response.getCode(), 403); - } - /** - * Checks that status of some entity job is equal to expected. Method can wait - * 100 seconds for expected status. - * - * @param oozieClient OozieClient - * @param entityType FEED or PROCESS - * @param data feed or proceess XML - * @param expectedStatus expected Job.Status of entity - * @throws OozieClientException - */ - public static void checkStatus(OozieClient oozieClient, EntityType entityType, String data, - Job.Status expectedStatus) - throws OozieClientException { - String name = null; - if (entityType == EntityType.FEED) { - name = Util.readEntityName(data); - } else if (entityType == EntityType.PROCESS) { - name = Util.readEntityName(data); - } - Assert.assertEquals( - OozieUtil.verifyOozieJobStatus(oozieClient, name, entityType, expectedStatus), true, - "Status should be " + expectedStatus); - } - - /** - * Checks that status of some entity job is equal to expected. Method can wait - * 100 seconds for expected status. - * - * @param oozieClient OozieClient - * @param entityType FEED or PROCESS - * @param bundle Bundle with feed or process data - * @param expectedStatus expected Job.Status of entity - * @throws OozieClientException - */ - public static void checkStatus(OozieClient oozieClient, EntityType entityType, Bundle bundle, - Job.Status expectedStatus) - throws OozieClientException { - String data = null; - if (entityType == EntityType.FEED) { - data = bundle.getDataSets().get(0); - } else if (entityType == EntityType.PROCESS) { - data = bundle.getProcessData(); - } - checkStatus(oozieClient, entityType, data, expectedStatus); - } - - /** - * Checks that status of some entity job is NOT equal to expected. - * - * @param oozieClient OozieClient - * @param entityType FEED or PROCESS - * @param data feed or proceess XML - * @param expectedStatus expected Job.Status of entity - * @throws OozieClientException - */ - public static void checkNotStatus(OozieClient oozieClient, EntityType entityType, String data, - Job.Status expectedStatus) - throws OozieClientException { - String processName = null; - if (entityType == EntityType.FEED) { - processName = Util.readEntityName(data); - } else if (entityType == EntityType.PROCESS) { - processName = Util.readEntityName(data); - } - Assert.assertNotEquals(OozieUtil.getOozieJobStatus(oozieClient, processName, - entityType), expectedStatus, "Status should not be " + expectedStatus); - } - - /** - * Checks that status of some entity job is NOT equal to expected. - * - * @param oozieClient OozieClient - * @param entityType FEED or PROCESS - * @param bundle Bundle with feed or process data - * @param expectedStatus expected Job.Status of entity - * @throws OozieClientException - */ - public static void checkNotStatus(OozieClient oozieClient, EntityType entityType, - Bundle bundle, Job.Status expectedStatus) - throws OozieClientException { - String data = null; - if (entityType == EntityType.FEED) { - data = bundle.getDataSets().get(0); - } else if (entityType == EntityType.PROCESS) { - data = bundle.getProcessData(); - } - checkNotStatus(oozieClient, entityType, data, expectedStatus); - } - - /** - * Checks size of the content a two locations. - * - * @param firstPath path to the first location - * @param secondPath path to the second location - * @param fs hadoop file system for the locations - * @throws IOException - */ - public static void checkContentSize(String firstPath, String secondPath, FileSystem fs) throws - IOException { - final ContentSummary firstSummary = fs.getContentSummary(new Path(firstPath)); - final ContentSummary secondSummary = fs.getContentSummary(new Path(secondPath)); - LOGGER.info(firstPath + " : firstSummary = " + firstSummary.toString(false)); - LOGGER.info(secondPath + " : secondSummary = " + secondSummary.toString(false)); - Assert.assertEquals(firstSummary.getLength(), secondSummary.getLength(), - "Contents at the two locations don't have same size."); - } - - /** - * Fail the test because of the supplied exception. - * @param e exception - */ - public static void fail(Exception e) { - LOGGER.info("Got exception: " + ExceptionUtils.getStackTrace(e)); - Assert.fail("Failing because of exception."); - } - - public static void assertEmpty(String str, String message) { - if (StringUtils.isNotEmpty(str)) { - Assert.fail(String.format("%s expected [empty string/null] found [%s]", message, str)); - } - } - - public static <E> void assertEmpty(Collection<E> collection, String message) { - if (!collection.isEmpty()) { - Assert.fail( - String.format("%s expected [empty collection] found [%s]", message, collection)); - } - } - public static void assertNotEmpty(String str, String message) { - if (StringUtils.isEmpty(str)) { - Assert.fail(String.format("%s expected non-empty string found [%s]", message, str)); - } - } - - /** - * Checks that job logs are copied to user defined cluster staging path. - * - * @param logFlag denotes whether is is failed/succeeded log - * @param entityName name of entity - * @param clusterFS hadoop file system for the locations - * @param entityType feed or process - */ - public static boolean assertPath(boolean logFlag, String entityName, FileSystem clusterFS, - String entityType) throws Exception { - String stagingDir= MerlinConstants.STAGING_LOCATION; - String path=stagingDir+"/falcon/workflows/"+ entityType + "/" + entityName +"/logs"; - List<Path> logmoverPaths = HadoopUtil - .getAllFilesRecursivelyHDFS(clusterFS, new Path(HadoopUtil.cutProtocol(path))); - String part = logFlag ? "SUCCEEDED" : "FAILED"; - for (Path logmoverPath : logmoverPaths) { - if (logmoverPath.toString().contains(part)) { - return true; - } - } - return false; - } - - /** - * Checks that job logs are copied to user defined cluster staging path. - * - * @param logFlag denotes whether is is failed/succeeded log - * @param entityName name of entity - * @param clusterFS hadoop file system for the locations - * @param entityType feed or process - * @param message message returned if assert fails - */ - public static void assertLogMoverPath(boolean logFlag, String entityName, FileSystem clusterFS, - String entityType, String message) throws Exception { - Assert.assertTrue(assertPath(logFlag, entityName, clusterFS, entityType), message); - } - - /** - * Checks that API Response status is FAILED. - * - * @param response APIResult - * @throws JAXBException - */ - public static void assertFailedInstance(APIResult response) throws JAXBException { - Assert.assertEquals(response.getStatus(), APIResult.Status.FAILED, - "Status should be FAILED. Message: " + response.getMessage()); - Assert.assertNotNull(response.getMessage(), "response message should not be null"); - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/BundleUtil.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/BundleUtil.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/BundleUtil.java deleted file mode 100644 index 16ff6cb..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/BundleUtil.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.falcon.entity.v0.cluster.ClusterLocationType; -import org.apache.falcon.entity.v0.cluster.Interface; -import org.apache.falcon.entity.v0.cluster.Interfacetype; -import org.apache.falcon.entity.v0.cluster.Location; -import org.apache.falcon.regression.Entities.ClusterMerlin; -import org.apache.falcon.regression.Entities.FeedMerlin; -import org.apache.falcon.regression.Entities.ProcessMerlin; -import org.apache.falcon.regression.core.bundle.Bundle; -import org.apache.falcon.regression.core.enumsAndConstants.MerlinConstants; -import org.apache.falcon.regression.core.helpers.ColoHelper; -import org.apache.falcon.regression.core.response.ServiceResponse; -import org.apache.hadoop.security.authentication.client.AuthenticationException; -import org.apache.log4j.Logger; -import org.testng.Assert; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * util methods related to bundle. - */ -public final class BundleUtil { - private BundleUtil() { - throw new AssertionError("Instantiating utility class..."); - } - private static final Logger LOGGER = Logger.getLogger(BundleUtil.class); - - public static Bundle readFeedReplicationBundle() throws IOException { - return readBundleFromFolder("FeedReplicationBundles"); - } - - public static Bundle readLateDataBundle() throws IOException { - return readBundleFromFolder("LateDataBundles"); - } - - public static Bundle readRetryBundle() throws IOException { - return readBundleFromFolder("RetryTests"); - } - - public static Bundle readRetentionBundle() throws IOException { - return readBundleFromFolder("RetentionBundles"); - } - - public static Bundle readELBundle() throws IOException { - return readBundleFromFolder("ELbundle"); - } - - public static Bundle readHCatBundle() throws IOException { - return readBundleFromFolder("hcat"); - } - - public static Bundle readHCat2Bundle() throws IOException { - return readBundleFromFolder("hcat_2"); - } - - public static Bundle readUpdateBundle() throws IOException { - return readBundleFromFolder("updateBundle"); - } - - public static Bundle readCombinedActionsBundle() throws IOException { - return readBundleFromFolder("combinedActions"); - } - - private static Bundle readBundleFromFolder(final String folderPath) throws IOException { - LOGGER.info("Loading xmls from directory: " + folderPath); - File directory = null; - try { - directory = new File(BundleUtil.class.getResource("/" + folderPath).toURI()); - } catch (URISyntaxException e) { - Assert.fail("could not find dir: " + folderPath); - } - final Collection<File> list = FileUtils.listFiles(directory, new String[] {"xml"}, true); - File[] files = list.toArray(new File[list.size()]); - Arrays.sort(files); - String clusterData = ""; - final List<String> dataSets = new ArrayList<>(); - String processData = ""; - - for (File file : files) { - LOGGER.info("Loading data from path: " + file.getAbsolutePath()); - final String data = IOUtils.toString(file.toURI()); - - if (data.contains("uri:falcon:cluster:0.1")) { - LOGGER.info("data been added to cluster"); - ClusterMerlin clusterMerlin = new ClusterMerlin(data); - //set ACL - clusterMerlin.setACL(MerlinConstants.CURRENT_USER_NAME, - MerlinConstants.CURRENT_USER_GROUP, "*"); - //set staging and working locations - clusterMerlin.getLocations().getLocations().clear(); - final Location staging = new Location(); - staging.setName(ClusterLocationType.STAGING); - staging.setPath(MerlinConstants.STAGING_LOCATION); - clusterMerlin.getLocations().getLocations().add(staging); - final Location working = new Location(); - working.setName(ClusterLocationType.WORKING); - working.setPath(MerlinConstants.WORKING_LOCATION); - clusterMerlin.getLocations().getLocations().add(working); - final Location temp = new Location(); - temp.setName(ClusterLocationType.TEMP); - temp.setPath(MerlinConstants.TEMP_LOCATION); - clusterMerlin.getLocations().getLocations().add(temp); - final String protectionPropName = "hadoop.rpc.protection"; - final String protectionPropValue = Config.getProperty(protectionPropName); - if (StringUtils.isNotEmpty(protectionPropValue)) { - clusterMerlin.withProperty(protectionPropName, protectionPropValue.trim()); - } - clusterData = clusterMerlin.toString(); - } else if (data.contains("uri:falcon:feed:0.1")) { - LOGGER.info("data been added to feed"); - FeedMerlin feedMerlin = new FeedMerlin(data); - feedMerlin.setACL(MerlinConstants.CURRENT_USER_NAME, - MerlinConstants.CURRENT_USER_GROUP, "*"); - dataSets.add(feedMerlin.toString()); - } else if (data.contains("uri:falcon:process:0.1")) { - LOGGER.info("data been added to process"); - ProcessMerlin processMerlin = new ProcessMerlin(data); - processMerlin.setACL(MerlinConstants.CURRENT_USER_NAME, - MerlinConstants.CURRENT_USER_GROUP, "*"); - processData = processMerlin.toString(); - } - } - Assert.assertNotNull(clusterData, "expecting cluster data to be non-empty"); - Assert.assertTrue(!dataSets.isEmpty(), "expecting feed data to be non-empty"); - return new Bundle(clusterData, dataSets, processData); - } - - public static void submitAllClusters(ColoHelper prismHelper, Bundle... b) - throws IOException, URISyntaxException, AuthenticationException, InterruptedException { - for (Bundle aB : b) { - ServiceResponse r = prismHelper.getClusterHelper().submitEntity(aB.getClusters().get(0)); - Assert.assertTrue(r.getMessage().contains("SUCCEEDED")); - - } - } - - /** - * Configures cluster definition according to provided properties. - * @param cluster cluster which should be configured - * @param prefix current cluster prefix - * @return modified cluster definition - */ - public static ClusterMerlin getEnvClusterXML(String cluster, String prefix) { - ClusterMerlin clusterObject = new ClusterMerlin(cluster); - if ((null == prefix) || prefix.isEmpty()) { - prefix = ""; - } else { - prefix = prefix + "."; - } - String hcatEndpoint = Config.getProperty(prefix + "hcat_endpoint"); - - //now read and set relevant values - for (Interface iface : clusterObject.getInterfaces().getInterfaces()) { - if (iface.getType() == Interfacetype.READONLY) { - iface.setEndpoint(Config.getProperty(prefix + "cluster_readonly")); - } else if (iface.getType() == Interfacetype.WRITE) { - iface.setEndpoint(Config.getProperty(prefix + "cluster_write")); - } else if (iface.getType() == Interfacetype.EXECUTE) { - iface.setEndpoint(Config.getProperty(prefix + "cluster_execute")); - } else if (iface.getType() == Interfacetype.WORKFLOW) { - iface.setEndpoint(Config.getProperty(prefix + "oozie_url")); - } else if (iface.getType() == Interfacetype.MESSAGING) { - iface.setEndpoint(Config.getProperty(prefix + "activemq_url")); - } else if (iface.getType() == Interfacetype.REGISTRY) { - iface.setEndpoint(hcatEndpoint); - } - } - //set colo name: - clusterObject.setColo(Config.getProperty(prefix + "colo")); - // properties in the cluster needed when secure mode is on - if (MerlinConstants.IS_SECURE) { - // add the namenode principal to the properties object - clusterObject.withProperty("dfs.namenode.kerberos.principal", - Config.getProperty(prefix + "namenode.kerberos.principal", "none")); - - // add the hive meta store principal to the properties object - clusterObject.withProperty("hive.metastore.kerberos.principal", - Config.getProperty(prefix + "hive.metastore.kerberos.principal", "none")); - - // Until oozie has better integration with secure hive we need to send the properties to - // falcon. - // hive.metastore.sasl.enabled = true - clusterObject.withProperty("hive.metastore.sasl.enabled", "true"); - // Only set the metastore uri if its not empty or null. - } - String hiveMetastoreUris = Config.getProperty(prefix + "hive.metastore.uris"); - if (StringUtils.isNotBlank(hiveMetastoreUris)) { - //hive.metastore.uris - clusterObject.withProperty("hive.metastore.uris", hiveMetastoreUris); - } - String hiveServer2Uri = Config.getProperty(prefix + "hive.server2.uri"); - if (StringUtils.isNotBlank(hiveServer2Uri)) { - //hive.metastore.uris - clusterObject.withProperty("hive.server2.uri", hiveServer2Uri); - } - return clusterObject; - } - - public static List<ClusterMerlin> getClustersFromStrings(List<String> clusterStrings) { - List<ClusterMerlin> clusters = new ArrayList<>(); - for (String clusterString : clusterStrings) { - clusters.add(new ClusterMerlin(clusterString)); - } - return clusters; - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/CleanupUtil.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/CleanupUtil.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/CleanupUtil.java deleted file mode 100644 index 225bc5b..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/CleanupUtil.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.falcon.regression.core.helpers.ColoHelper; -import org.apache.falcon.regression.core.helpers.entity.AbstractEntityHelper; -import org.apache.falcon.regression.core.response.ServiceResponse; -import org.apache.falcon.resource.EntityList; -import org.apache.hadoop.security.authentication.client.AuthenticationException; -import org.apache.log4j.Logger; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.IOException; -import java.io.StringReader; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; - -/** - * util methods related to conf. - */ -public final class CleanupUtil { - private CleanupUtil() { - throw new AssertionError("Instantiating utility class..."); - } - private static final Logger LOGGER = Logger.getLogger(CleanupUtil.class); - - public static List<String> getAllEntitiesOfOneType(AbstractEntityHelper entityManagerHelper, - String user) { - return getEntitiesWithPrefix(entityManagerHelper, user, ""); - } - - public static List<String> getEntitiesWithPrefix(AbstractEntityHelper entityHelper, - String user, String namePrefix) { - final EntityList entityList; - try { - entityList = getEntitiesResultOfOneType(entityHelper, user); - } catch (Exception e) { - LOGGER.error("Caught exception: " + ExceptionUtils.getStackTrace(e)); - return null; - } - List<String> entities = new ArrayList<>(); - if (entityList.getElements() != null) { - for (EntityList.EntityElement entity : entityList.getElements()) { - if (entity.name.startsWith(namePrefix)) { - entities.add(entity.name); - } - } - } - return entities; - } - - private static EntityList getEntitiesResultOfOneType( - AbstractEntityHelper entityManagerHelper, String user) - throws IOException, URISyntaxException, AuthenticationException, JAXBException, - InterruptedException { - final ServiceResponse clusterResponse = entityManagerHelper.listAllEntities(null, user); - JAXBContext jc = JAXBContext.newInstance(EntityList.class); - Unmarshaller u = jc.createUnmarshaller(); - return (EntityList) u.unmarshal( - new StringReader(clusterResponse.getMessage())); - } - - public static void cleanEntitiesWithPrefix(ColoHelper prism, String namePrefix, String user) { - final List<String> processes = getEntitiesWithPrefix(prism.getProcessHelper(), user, namePrefix); - final List<String> feeds = getEntitiesWithPrefix(prism.getFeedHelper(), user, namePrefix); - final List<String> clusters = getEntitiesWithPrefix(prism.getClusterHelper(), user, namePrefix); - - for (String process : processes) { - deleteQuietlyByName(prism.getProcessHelper(), process, user); - } - for (String feed : feeds) { - deleteQuietlyByName(prism.getFeedHelper(), feed, user); - } - - for (String cluster : clusters) { - deleteQuietlyByName(prism.getClusterHelper(), cluster, user); - } - } - - private static void deleteQuietlyByName(AbstractEntityHelper helper, String entityName, String user) { - try { - helper.deleteByName(entityName, user); - } catch (Exception e) { - LOGGER.info("Caught exception: " + ExceptionUtils.getStackTrace(e)); - } - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Config.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Config.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Config.java deleted file mode 100644 index ba509e4..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Config.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import org.apache.commons.configuration.AbstractConfiguration; -import org.apache.commons.configuration.CompositeConfiguration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.commons.configuration.SystemConfiguration; -import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy; -import org.apache.log4j.Logger; -import org.testng.Assert; - -/** Class for reading properties from Merlin.properties file. */ -public final class Config { - private static final Logger LOGGER = Logger.getLogger(Config.class); - - private static final String MERLIN_PROPERTIES = "Merlin.properties"; - private static final Config INSTANCE = new Config(MERLIN_PROPERTIES); - - private AbstractConfiguration confObj; - private Config(String propFileName) { - try { - initConfig(propFileName); - } catch (ConfigurationException e) { - Assert.fail("Could not read properties because of exception: " + e); - } - } - - private void initConfig(String propFileName) throws ConfigurationException { - CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); - LOGGER.info("Going to add properties from system properties."); - compositeConfiguration.addConfiguration(new SystemConfiguration()); - - LOGGER.info("Going to read properties from: " + propFileName); - final PropertiesConfiguration merlinConfig = - new PropertiesConfiguration(Config.class.getResource("/" + propFileName)); - //if changed configuration will be reloaded within 2 min - final FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); - reloadingStrategy.setRefreshDelay(2 * 60 * 1000); - merlinConfig.setReloadingStrategy(reloadingStrategy); - compositeConfiguration.addConfiguration(merlinConfig); - this.confObj = compositeConfiguration; - } - - public static String getProperty(String key) { - return INSTANCE.confObj.getString(key); - } - - public static String[] getStringArray(String key) { - return INSTANCE.confObj.getStringArray(key); - } - - public static String getProperty(String key, String defaultValue) { - return INSTANCE.confObj.getString(key, defaultValue); - } - - public static boolean getBoolean(String key, boolean defaultValue) { - return INSTANCE.confObj.getBoolean(key, defaultValue); - } - - public static int getInt(String key, int defaultValue) { - return INSTANCE.confObj.getInt(key, defaultValue); - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/EntityLineageUtil.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/EntityLineageUtil.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/EntityLineageUtil.java deleted file mode 100644 index 3b6314f..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/EntityLineageUtil.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import org.apache.falcon.regression.core.enumsAndConstants.ResponseErrors; -import org.apache.falcon.resource.LineageGraphResult; -import org.apache.falcon.resource.TriageResult; -import org.apache.log4j.Logger; -import org.joda.time.DateTime; -import org.testng.Assert; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - - -/** - *Util function related to entity lineage. - */ -public final class EntityLineageUtil{ - - private static final Logger LOGGER = Logger.getLogger(EntityLineageUtil.class); - - /** - * Enum to represent entity role in pipeline. - */ - public enum PipelineEntityType { - PROCESS, INPUT_FEED, OUTPUT_FEED - } - - private EntityLineageUtil() { - throw new AssertionError("Instantiating utility class..."); - } - - /** - * Validates entity lineage results. - * @param lineageGraphResult entity lineage result - * @param expectedVertices array of expected vertices - * @param expectedEdgeArray array of expected edges - */ - public static void validateLineageGraphResult(LineageGraphResult lineageGraphResult, String[] expectedVertices, - LineageGraphResult.Edge[] expectedEdgeArray) { - String[] actualVertices; - LineageGraphResult.Edge[] actualEdgeArray; - Set<String> actualVerticesSet = new HashSet<>(); - Set<LineageGraphResult.Edge> actualEdgeSet = new HashSet<>(); - - try { - actualVertices = lineageGraphResult.getVertices(); - actualVerticesSet = new HashSet<>(Arrays.asList(actualVertices)); - } catch (NullPointerException e) { - Assert.assertEquals(expectedVertices.length, 0); - } - try { - actualEdgeArray = lineageGraphResult.getEdges(); - actualEdgeSet = new HashSet<>(Arrays.asList(actualEdgeArray)); - } catch (NullPointerException e) { - Assert.assertEquals(expectedEdgeArray.length, 0); - } - - Set<LineageGraphResult.Edge> expectedEdgeSet = new HashSet<>(Arrays.asList(expectedEdgeArray)); - Set<String> expectedVerticesSet = new HashSet<>(Arrays.asList(expectedVertices)); - - Assert.assertEquals(actualEdgeSet, expectedEdgeSet, "Edges dont match"); - Assert.assertEquals(actualVerticesSet, expectedVerticesSet, "Vertices dont match"); - } - - /** - * Validates that failed response contains specific error message. - * @param triageResult response - * @param error expected error - */ - public static void validateError(TriageResult triageResult, ResponseErrors error) { - AssertUtil.assertFailed(triageResult); - Assert.assertTrue(triageResult.getMessage().contains(error.getError()), - "Error should contain '" + error + "'"); - } - - /** - * Produces list of expected vertices and edges in triage result. - */ - public static LineageGraphResult getExpectedResult(int bundleIndx, - Map<PipelineEntityType, List<String>> entityNamesMap, - List<Integer> inputFeedFrequencies, String entityName, - String clusterName, String startTime) { - List<String> processNames = entityNamesMap.get(PipelineEntityType.PROCESS); - List<String> inputFeedNames = entityNamesMap.get(PipelineEntityType.INPUT_FEED); - List<String> outputFeedNames = entityNamesMap.get(PipelineEntityType.OUTPUT_FEED); - List<String> vertices = new ArrayList<>(); - List<LineageGraphResult.Edge> edges = new ArrayList<>(); - final String startTimeMinus20 = TimeUtil.addMinsToTime(startTime, -20); - String vertexTemplate = "name: %s, type: %s, cluster: %s, instanceTime: %s, tags: %s"; - for (int i = 0; i <= bundleIndx; ++i) { - //add vertex of i-th bundle process - boolean isTerminalInstance = processNames.contains(entityName) && i == bundleIndx; - String tag = isTerminalInstance ? "[WAITING]" : "Output[WAITING]"; - final String processVertex = String.format(vertexTemplate, - processNames.get(i), "PROCESS", clusterName, startTime, tag); - vertices.add(processVertex); - - //add all input feed vertices & edges for i-th bundle - LineageGraphResult.Edge edge; - String feedVertex; - for (DateTime dt = new DateTime(startTime); !dt.isBefore(new DateTime(startTimeMinus20)); - dt = dt.minusMinutes(inputFeedFrequencies.get(i))) { - feedVertex = String.format(vertexTemplate, inputFeedNames.get(i), "FEED", - clusterName, TimeUtil.dateToOozieDate(dt.toDate()), "Input[MISSING]"); - edge = new LineageGraphResult.Edge(feedVertex, processVertex, "consumed by"); - vertices.add(feedVertex); - edges.add(edge); - } - //add output feed edge for i-th bundle - tag = (outputFeedNames.contains(entityName) && i == bundleIndx) ? "[MISSING]" : "Input[MISSING]"; - feedVertex = String.format(vertexTemplate, outputFeedNames.get(i), "FEED", clusterName, startTime, tag); - isTerminalInstance = i == bundleIndx && outputFeedNames.contains(entityName); - if (i < bundleIndx || isTerminalInstance) { - edge = new LineageGraphResult.Edge(processVertex, feedVertex, "produces"); - edges.add(edge); - } - //add output feed vertex only if it is terminal; it will be added as the input for next bundle otherwise - if (isTerminalInstance) { - vertices.add(feedVertex); - } - } - LineageGraphResult lineageGraphResult = new LineageGraphResult(); - lineageGraphResult.setVertices(vertices.toArray(new String[vertices.size()])); - lineageGraphResult.setEdges(edges.toArray(new LineageGraphResult.Edge[edges.size()])); - return lineageGraphResult; - } - -} - http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/ExecUtil.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/ExecUtil.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/ExecUtil.java deleted file mode 100644 index a792f62..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/ExecUtil.java +++ /dev/null @@ -1,211 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import com.jcraft.jsch.ChannelExec; -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import com.jcraft.jsch.UserInfo; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.DefaultExecutor; -import org.apache.commons.exec.ExecuteWatchdog; -import org.apache.commons.exec.PumpStreamHandler; -import org.apache.commons.io.IOUtils; -import org.apache.falcon.regression.core.supportClasses.ExecResult; -import org.apache.log4j.Logger; -import org.testng.Assert; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -/** - * util methods related to exec. - */ -public final class ExecUtil { - private ExecUtil() { - throw new AssertionError("Instantiating utility class..."); - } - private static final Logger LOGGER = Logger.getLogger(ExecUtil.class); - - static List<String> runRemoteScriptAsSudo(final String hostName, final String userName, - final String password, final String command, - final String runAs, final String identityFile) throws - JSchException, IOException { - JSch jsch = new JSch(); - Session session = jsch.getSession(userName, hostName, 22); - // only set the password if its not empty - if (null != password && !password.isEmpty()) { - session.setUserInfo(new HardcodedUserInfo(password)); - } - Properties config = new Properties(); - config.setProperty("StrictHostKeyChecking", "no"); - config.setProperty("UserKnownHostsFile", "/dev/null"); - // only set the password if its not empty - if (null == password || password.isEmpty()) { - jsch.addIdentity(identityFile); - } - session.setConfig(config); - session.connect(); - Assert.assertTrue(session.isConnected(), "The session was not connected correctly!"); - - List<String> data = new ArrayList<>(); - - ChannelExec channel = (ChannelExec) session.openChannel("exec"); - channel.setPty(true); - String runCmd; - if (null == runAs || runAs.isEmpty()) { - runCmd = "sudo -S -p '' " + command; - } else { - runCmd = String.format("sudo su - %s -c '%s'", runAs, command); - } - if (userName.equals(runAs)) { - runCmd = command; - } - LOGGER.info( - "host_name: " + hostName + " user_name: " + userName + " password: " + password - + - " command: " +runCmd); - channel.setCommand(runCmd); - InputStream in = channel.getInputStream(); - OutputStream out = channel.getOutputStream(); - channel.setErrStream(System.err); - channel.connect(); - TimeUtil.sleepSeconds(20); - // only print the password if its not empty - if (null != password && !password.isEmpty()) { - out.write((password + "\n").getBytes()); - out.flush(); - } - - //save console output to data - BufferedReader r = new BufferedReader(new InputStreamReader(in)); - String line; - while (true) { - while ((line=r.readLine())!=null) { - LOGGER.debug(line); - data.add(line); - } - if (channel.isClosed()) { - break; - } - } - - byte[] tmp = new byte[1024]; - while (true) { - while (in.available() > 0) { - int i = in.read(tmp, 0, 1024); - if (i < 0) { - break; - } - LOGGER.info(new String(tmp, 0, i)); - } - if (channel.isClosed()) { - LOGGER.info("exit-status: " + channel.getExitStatus()); - break; - } - TimeUtil.sleepSeconds(1); - } - - IOUtils.closeQuietly(r); - IOUtils.closeQuietly(in); - channel.disconnect(); - session.disconnect(); - IOUtils.closeQuietly(out); - return data; - } - - public static ExecResult executeCommand(String command) { - return executeCommand(CommandLine.parse(command)); - } - - public static ExecResult executeCommand(CommandLine commandLine) { - LOGGER.info("Command to be executed: " + commandLine); - DefaultExecutor executor = new DefaultExecutor(); - executor.setWatchdog(new ExecuteWatchdog(5 * 1000)); //timeout of 5 seconds - final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - final ByteArrayOutputStream errStream = new ByteArrayOutputStream(); - executor.setStreamHandler(new PumpStreamHandler(outStream, errStream)); - int exitVal = 1; - String exception = ""; - try { - exitVal = executor.execute(commandLine); - } catch (IOException e) { - LOGGER.warn("Caught exception: " + e); - exception = e.toString(); - } - final String output = outStream.toString(); - String errors = errStream.toString(); - errors = errors.isEmpty() ? exception : errors; - - LOGGER.info("exitVal: " + exitVal); - LOGGER.info("output: " + output); - LOGGER.info("errors: " + errors); - return new ExecResult(commandLine, exitVal, output.trim(), errors.trim()); - } - - public static int executeCommandGetExitCode(String command) { - return executeCommand(command).getExitVal(); - } - - public static String executeCommandGetOutput(String command) { - return executeCommand(command).getOutput(); - } - - private static final class HardcodedUserInfo implements UserInfo { - - private final String password; - - private HardcodedUserInfo(String password) { - this.password = password; - } - - public String getPassphrase() { - return null; - } - - public String getPassword() { - return password; - } - - public boolean promptPassword(String s) { - return true; - } - - public boolean promptPassphrase(String s) { - return true; - } - - public boolean promptYesNo(String s) { - return true; - } - - public void showMessage(String s) { - LOGGER.info("message = " + s); - } - } - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/FileUtil.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/FileUtil.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/FileUtil.java deleted file mode 100644 index a969f1f..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/FileUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; - -import java.io.File; -import java.io.IOException; -/** - * Util class for local files. - */ -public final class FileUtil { - private static final Logger LOGGER = Logger.getLogger(FileUtil.class); - private FileUtil() { - } - - /** - * Writes an entity to a file and returns the filename. - * @param entity to be written - * @return name of the file - * @throws IOException - */ - public static String writeEntityToFile(String entity) throws IOException { - final String entityName = Util.readEntityName(entity); - final File entityFile = new File(entityName + ".xml"); - LOGGER.info("attempting to write: " + entityName + " at location " - + entityFile.getAbsolutePath()); - FileUtils.write(entityFile, entity); - return entityFile.getAbsolutePath(); - } -} http://git-wip-us.apache.org/repos/asf/falcon/blob/8e49379d/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Generator.java ---------------------------------------------------------------------- diff --git a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Generator.java b/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Generator.java deleted file mode 100644 index 5842ced..0000000 --- a/falcon-regression/merlin-core/src/main/java/org/apache/falcon/regression/core/util/Generator.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.falcon.regression.core.util; - -/** Generator class for generating predictable names and paths. */ -public final class Generator { - private final String prefix; - private final String postfix; - private final String formatString; - private int count; - - - private Generator(String prefix, String postfix, String formatString) { - this.prefix = prefix; - this.postfix = postfix; - this.count = 0; - this.formatString = formatString; - } - - public String generate() { - count++; - return String.format(formatString, prefix, count, postfix); - } - - public static Generator getNameGenerator(String prefix, String postfix) { - return new Generator(prefix, postfix, "%s%03d-%s"); - } - - public static Generator getHadoopPathGenerator(String prefix, String postfix) { - return new Generator(prefix, postfix, "%s_%03d%s"); - } -}
