You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/09/17 07:18:17 UTC
stratos git commit: Fixing STRATOS-1566: PCA Git artifact delete issue
Repository: stratos
Updated Branches:
refs/heads/stratos-4.1.x d0bc92795 -> e757f11ef
Fixing STRATOS-1566: PCA Git artifact delete issue
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e757f11e
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e757f11e
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e757f11e
Branch: refs/heads/stratos-4.1.x
Commit: e757f11ef7a14fe039d4e9d250bb86ee0f8c9553
Parents: d0bc927
Author: Akila Perera <ra...@gmail.com>
Authored: Thu Sep 17 10:47:34 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Thu Sep 17 10:47:50 2015 +0530
----------------------------------------------------------------------
.../modules/artifactmgt/git/agentgithandler.py | 37 ++++++++++++++------
.../tests/ADCMTAppTenantUserTestCase.java | 3 +-
.../integration/tests/ADCMTAppTestCase.java | 3 +-
.../agent/integration/tests/ADCTestCase.java | 30 +++++++++++-----
.../integration/tests/AgentStartupTestCase.java | 4 +--
.../tests/PythonAgentIntegrationTest.java | 9 +++--
6 files changed, 56 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/e757f11e/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
index 22fe816..d8da842 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/artifactmgt/git/agentgithandler.py
@@ -162,14 +162,22 @@ class AgentGitHandler:
@staticmethod
def pull(git_repo):
# git reset to make sure no uncommitted changes are present before the pull, no conflicts will occur
- AgentGitHandler.execute_git_command(["reset", "--hard"], git_repo.local_repo_path)
+ (output, errors) = AgentGitHandler.execute_git_command(["status"], git_repo.local_repo_path)
+ AgentGitHandler.log.info("Executed git status with output: %r" % output)
+
+ # check if modified files are present
+ modified = AgentGitHandler.has_modified_files(git_repo.local_repo_path)
+ if modified:
+ AgentGitHandler.log.info("Unstaged files exist in working directory. Aborting Git pull...")
+ return
# HEAD before pull
(init_head, init_errors) = AgentGitHandler.execute_git_command(["rev-parse", "HEAD"], git_repo.local_repo_path)
try:
repo = Repo(git_repo.local_repo_path)
- repo.remotes.origin.pull()
+ output = repo.remotes.origin.pull(rebase=True)
+ AgentGitHandler.log.info("Git pull rebase executed in checkout job")
if repo.is_dirty():
raise GitRepositorySynchronizationException("Git pull operation left the repository in dirty state")
except (GitCommandError, GitRepositorySynchronizationException) as e:
@@ -321,7 +329,7 @@ class AgentGitHandler:
git_repo = AgentGitHandler.get_repo(repo_info.tenant_id)
if git_repo is None:
# not cloned yet
- raise GitRepositorySynchronizationException("Not a valid repository to push from. Aborting")
+ AgentGitHandler.log.error("Not a valid repository to push from. Aborting Git push...")
# Get initial HEAD so in case if push fails it can be reverted to this hash
# This way, commit and push becomes an single operation. No intermediate state will be left behind.
@@ -367,6 +375,11 @@ class AgentGitHandler:
# push to remote
try:
repo = Repo(git_repo.local_repo_path)
+
+ # pull and rebase before pushing to remote repo
+ output = repo.remotes.origin.pull(rebase=True)
+ AgentGitHandler.log.info("Git pull rebase executed before pushing to remote")
+
push_info = repo.remotes.origin.push()
if str(push_info[0].summary) is "[rejected] (fetch first)":
# need to pull
@@ -480,23 +493,25 @@ class ArtifactUpdateTask(AbstractAsyncScheduledTask):
self.repo_info = repo_info
self.auto_checkout = auto_checkout
self.auto_commit = auto_commit
+ self.invocation_count = 0
def execute_task(self):
- if self.auto_checkout:
- try:
- self.log.debug("Running checkout job")
- AgentGitHandler.checkout(self.repo_info)
- # TODO: run updated scheduler extension
- except GitRepositorySynchronizationException as e:
- self.log.exception("Auto checkout task failed: %s" % e.get_message())
+ self.invocation_count += 1
if self.auto_commit:
try:
- self.log.debug("Running commit job")
+ self.log.debug("Running commit job # %s" % self.invocation_count)
AgentGitHandler.push(self.repo_info)
except GitRepositorySynchronizationException as e:
self.log.exception("Auto commit failed: %s" % e.get_message())
+ if self.auto_checkout:
+ try:
+ self.log.debug("Running checkout job # %s" % self.invocation_count)
+ AgentGitHandler.checkout(self.repo_info)
+ # TODO: run updated scheduler extension
+ except GitRepositorySynchronizationException as e:
+ self.log.exception("Auto checkout task failed: %s" % e.get_message())
class GitRepository:
"""
http://git-wip-us.apache.org/repos/asf/stratos/blob/e757f11e/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
index fa5168e..87e216b 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTenantUserTestCase.java
@@ -63,7 +63,7 @@ public class ADCMTAppTenantUserTestCase extends PythonAgentIntegrationTest {
System.setProperty("jndi.properties.dir", getCommonResourcesPath());
// start Python agent with configurations provided in resource path
- super.setup();
+ super.setup(ADC_TIMEOUT);
// Simulate server socket
startServerSocket(8080);
@@ -151,7 +151,6 @@ public class ADCMTAppTenantUserTestCase extends PythonAgentIntegrationTest {
publishEvent(getArtifactUpdatedEventForPublicRepo());
log.info("Artifact updated event published");
}
- log.info(line);
}
}
sleep(1000);
http://git-wip-us.apache.org/repos/asf/stratos/blob/e757f11e/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
index de479b4..c07aecb 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCMTAppTestCase.java
@@ -65,7 +65,7 @@ public class ADCMTAppTestCase extends PythonAgentIntegrationTest {
System.setProperty("jndi.properties.dir", getCommonResourcesPath());
// start Python agent with configurations provided in resource path
- super.setup();
+ super.setup(ADC_TIMEOUT);
// Simulate server socket
startServerSocket(8080);
@@ -153,7 +153,6 @@ public class ADCMTAppTestCase extends PythonAgentIntegrationTest {
publishEvent(getArtifactUpdatedEventForPublicRepo());
log.info("Artifact updated event published");
}
- log.info(line);
}
}
sleep(1000);
http://git-wip-us.apache.org/repos/asf/stratos/blob/e757f11e/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
index c5ed413..c836295 100755
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/ADCTestCase.java
@@ -66,7 +66,7 @@ public class ADCTestCase extends PythonAgentIntegrationTest {
System.setProperty("jndi.properties.dir", getCommonResourcesPath());
// start Python agent with configurations provided in resource path
- super.setup();
+ super.setup(ADC_TIMEOUT);
// Simulate server socket
startServerSocket(8080);
@@ -82,13 +82,17 @@ public class ADCTestCase extends PythonAgentIntegrationTest {
}
- @Test(timeOut = ADC_TIMEOUT)
- public void testADC() {
+ @Test(timeOut = ADC_TIMEOUT, groups = {"smoke"})
+ public void testADC() throws Exception {
startCommunicatorThread();
assertAgentActivation();
Thread adcTestThread = new Thread(new Runnable() {
@Override
public void run() {
+ String artifactFileName = "pca-live-" + UUID.randomUUID();
+ File file = new File(APPLICATION_PATH + File.separator + artifactFileName);
+ boolean fileCreated = false;
+ boolean fileDeleted = false;
log.info("Running ADC Test thread...");
// Send artifact updated event
publishEvent(getArtifactUpdatedEventForPrivateRepo());
@@ -103,17 +107,28 @@ public class ADCTestCase extends PythonAgentIntegrationTest {
if (line.contains("Git clone executed")) {
log.info("Agent has completed git clone. Asserting the operation...");
assertRepoClone(getArtifactUpdatedEventForPrivateRepo());
- File file = new File(APPLICATION_PATH + "/pca-live-" + UUID.randomUUID());
+
try {
- file.createNewFile();
+ if (!file.createNewFile()) {
+ throw new RuntimeException("Could not create [file] " + file.getAbsolutePath());
+ }
+ fileCreated = true;
}
catch (IOException e) {
log.error("Could not create file", e);
}
}
- if (line.contains("Pushed artifacts for tenant")) {
+ if (fileCreated && line.contains("Pushed artifacts for tenant")) {
log.info("ADC Test completed");
- hasADCTestCompleted = true;
+ if (!file.delete()) {
+ throw new RuntimeException("Could not delete [file] " + file.getAbsolutePath());
+ }
+ fileDeleted = true;
+ }
+ if (fileDeleted && line.contains("Git pull rebase executed in checkout job")) {
+ if (!file.exists()) {
+ hasADCTestCompleted = true;
+ }
}
}
}
@@ -165,7 +180,6 @@ public class ADCTestCase extends PythonAgentIntegrationTest {
publishEvent(getArtifactUpdatedEventForPrivateRepo());
log.info("Artifact updated event published");
}
- log.info(line);
}
}
sleep(1000);
http://git-wip-us.apache.org/repos/asf/stratos/blob/e757f11e/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
index 0ae872a..14f7bd9 100755
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/AgentStartupTestCase.java
@@ -41,7 +41,7 @@ import java.util.Properties;
public class AgentStartupTestCase extends PythonAgentIntegrationTest {
private static final Log log = LogFactory.getLog(AgentStartupTestCase.class);
- private static final int STARTUP_TIMEOUT = 300000;
+ private static final int STARTUP_TIMEOUT = 5 * 60000;
private static final String CLUSTER_ID = "php.php.domain";
private static final String DEPLOYMENT_POLICY_NAME = "deployment-policy-1";
private static final String AUTOSCALING_POLICY_NAME = "autoscaling-policy-1";
@@ -67,7 +67,7 @@ public class AgentStartupTestCase extends PythonAgentIntegrationTest {
System.setProperty("jndi.properties.dir", getCommonResourcesPath());
// start Python agent with configurations provided in resource path
- super.setup();
+ super.setup(STARTUP_TIMEOUT);
// Simulate server socket
startServerSocket(8080);
http://git-wip-us.apache.org/repos/asf/stratos/blob/e757f11e/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
----------------------------------------------------------------------
diff --git a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
index 52ee0ad..310a232 100644
--- a/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
+++ b/products/python-cartridge-agent/modules/integration/test-integration/src/test/java/org/apache/stratos/python/cartridge/agent/integration/tests/PythonAgentIntegrationTest.java
@@ -49,7 +49,6 @@ public class PythonAgentIntegrationTest {
private static final Log log = LogFactory.getLog(PythonAgentIntegrationTest.class);
protected BrokerService broker;
- public final long TIMEOUT = 5 * 60000;
public static final String NEW_LINE = System.getProperty("line.separator");
public static final String ACTIVEMQ_AMQP_BIND_ADDRESS = "activemq.amqp.bind.address";
public static final String ACTIVEMQ_MQTT_BIND_ADDRESS = "activemq.mqtt.bind.address";
@@ -78,7 +77,7 @@ public class PythonAgentIntegrationTest {
/**
* Setup method for test method testPythonCartridgeAgent
*/
- protected void setup() throws Exception {
+ protected void setup(int timeout) throws Exception {
// start ActiveMQ test server
startBroker();
@@ -134,7 +133,7 @@ public class PythonAgentIntegrationTest {
String agentPath = setupPythonAgent();
log.info("Python agent working directory name: " + PYTHON_AGENT_DIR_NAME);
log.info("Starting python cartridge agent...");
- this.outputStream = executeCommand("python " + agentPath + PATH_SEP + "agent.py");
+ this.outputStream = executeCommand("python " + agentPath + PATH_SEP + "agent.py", timeout);
}
@@ -408,7 +407,7 @@ public class PythonAgentIntegrationTest {
*
* @param commandText
*/
- protected ByteArrayOutputStreamLocal executeCommand(final String commandText) {
+ protected ByteArrayOutputStreamLocal executeCommand(final String commandText, int timeout) {
final ByteArrayOutputStreamLocal outputStream = new ByteArrayOutputStreamLocal();
try {
CommandLine commandline = CommandLine.parse(commandText);
@@ -418,7 +417,7 @@ public class PythonAgentIntegrationTest {
PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP +
PYTHON_AGENT_DIR_NAME));
exec.setStreamHandler(streamHandler);
- ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
+ ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
exec.setWatchdog(watchdog);
exec.execute(commandline, new ExecuteResultHandler() {
@Override