@Test (dependsOnMethods = "testDelete") public void testGitCreate() throws Exception { // push a new config file File testFlowFile = new File(GIT_CLONE_DIR + "/gobblin-config/testGroup/testFlow.pull"); testFlowFile.getParentFile().mkdirs(); Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value20\n", testFlowFile, Charsets.UTF_8); Collection<Spec> specs = this.gobblinServiceManager.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 0); // add, commit, push this.gitForPush.add().addFilepattern("gobblin-config/testGroup/testFlow.pull").call(); this.gitForPush.commit().setMessage("second commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call(); // polling is every 5 seconds, so wait twice as long and check TimeUnit.SECONDS.sleep(10); specs = this.gobblinServiceManager.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value20"); }
@Test(dependsOnMethods = "testAddConfig") public void testUpdateConfig() throws IOException, GitAPIException, URISyntaxException { // push an updated config file Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value2\n", testFlowFile, Charsets.UTF_8); // add, commit, push this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.commit().setMessage("Third commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitConfigMonitor.processGitConfigChanges(); Collection<Spec> specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value2"); }
@Test public void testAddConfig() throws IOException, GitAPIException, URISyntaxException { // push a new config file this.testGroupDir.mkdirs(); this.testFlowFile.createNewFile(); Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value1\n", testFlowFile, Charsets.UTF_8); // add, commit, push this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.commit().setMessage("Second commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitConfigMonitor.processGitConfigChanges(); Collection<Spec> specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value1"); }
@Test (dependsOnMethods = "testUpdateNode") public void testRemoveEdge() throws GitAPIException, IOException { // delete a config file edge1File.delete(); //Node1 has 1 edge before delete Set<FlowEdge> edgeSet = this.flowGraph.getEdges("node1"); Assert.assertEquals(edgeSet.size(), 1); // delete, commit, push DirCache ac = this.gitForPush.rm().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call(); RevCommit cc = this.gitForPush.commit().setMessage("Edge remove commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitFlowGraphMonitor.processGitConfigChanges(); //Check if edge1 has been deleted from the graph edgeSet = this.flowGraph.getEdges("node1"); Assert.assertTrue(edgeSet.size() == 0); }
.call(); this.gitForPush.commit().setMessage("Seventh commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
@Test(dependsOnMethods = "testUpdateConfig") public void testDeleteConfig() throws IOException, GitAPIException, URISyntaxException { // delete a config file testFlowFile.delete(); // flow catalog has 1 entry before the config is deleted Collection<Spec> specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); // add, commit, push DirCache ac = this.gitForPush.rm().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); RevCommit cc = this.gitForPush.commit().setMessage("Fourth commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitConfigMonitor.processGitConfigChanges(); specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 0); }
private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException { createNewFile(edgeDir, edgeFile, fileContents); // add, commit, push edge this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();
@Test (dependsOnMethods = "testAddNode") public void testUpdateEdge() throws IOException, GitAPIException, URISyntaxException, ExecutionException, InterruptedException { //Update edge1 file String fileContents = buildEdgeFileContents("node1", "node2", "edge1", "value2"); addEdge(this.edge1Dir, this.edge1File, fileContents); // add, commit, push this.gitForPush.add().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitFlowGraphMonitor.processGitConfigChanges(); //Check if new edge1 has been added to the FlowGraph testIfEdgeSuccessfullyAdded("node1", "node2", "edge1", "value2"); }
@Test (dependsOnMethods = "testRemoveEdge") public void testRemoveNode() throws GitAPIException, IOException { //delete node files node1File.delete(); node2File.delete(); //Ensure node1 and node2 are present in the graph before delete DataNode node1 = this.flowGraph.getNode("node1"); Assert.assertNotNull(node1); DataNode node2 = this.flowGraph.getNode("node2"); Assert.assertNotNull(node2); // delete, commit, push this.gitForPush.rm().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call(); this.gitForPush.rm().addFilepattern(formNodeFilePath(this.node2Dir.getName(), this.node2File.getName())).call(); this.gitForPush.commit().setMessage("Node remove commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitFlowGraphMonitor.processGitConfigChanges(); //Check if node1 and node 2 have been deleted from the graph node1 = this.flowGraph.getNode("node1"); Assert.assertNull(node1); node2 = this.flowGraph.getNode("node2"); Assert.assertNull(node2); }
.call(); this.gitForPush.commit().setMessage("Fifth commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call(); .call(); this.gitForPush.commit().setMessage("Sixth commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
private void addNode(File nodeDir, File nodeFile, String fileContents) throws IOException, GitAPIException { createNewFile(nodeDir, nodeFile, fileContents); // add, commit, push node this.gitForPush.add().addFilepattern(formNodeFilePath(nodeDir.getName(), nodeFile.getName())).call(); this.gitForPush.commit().setMessage("Node commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.add().addFilepattern(formNodeFilePath(this.node2Dir.getName(), this.node2File.getName())).call(); this.gitForPush.commit().setMessage("Add nodes commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.rm().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call(); this.gitForPush.commit().setMessage("Delete node1 and edge1 commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.add().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call(); this.gitForPush.commit().setMessage("Add node1 commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
@BeforeClass public void setup() throws Exception { cleanUpDir(TEST_DIR); // Create a bare repository RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED); this.remoteRepo = fileKey.open(false); this.remoteRepo.create(true); this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call(); // push an empty commit as a base for detecting changes this.gitForPush.commit().setMessage("First commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.config = ConfigBuilder.create() .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI, this.remoteRepo.getDirectory().getAbsolutePath()) .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/jobConfig") .addPrimitive(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, TEST_DIR + "flowCatalog") .addPrimitive(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5) .build(); this.flowCatalog = new FlowCatalog(config); this.flowCatalog.startAsync().awaitRunning(); this.gitConfigMonitor = new GitConfigMonitor(this.config, this.flowCatalog); this.gitConfigMonitor.setActive(true); }
@Signature public Memory push(String remote, ArrayMemory settings) throws GitAPIException { PushCommand push = getWrappedObject().push();
git.push() .call();
/** * Push code to remote repo * * @param path * @param remote * @param branchOrTag * @return * @throws GitException */ public static Path push(Path path, String remote, String branchOrTag) throws GitException { try (Git git = Git.open(path.toFile())) { git.push() .setRemote(remote) .setRefSpecs(new RefSpec(branchOrTag)) .call(); } catch (Throwable throwable) { throw new GitException("Fail to Push ", throwable); } return path; }
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }