use of io.fabric8.maven.docker.util.Task in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method activateInternal.
private void activateInternal() throws Exception {
LOGGER.info("Starting up GitDataStore " + this);
// Call the bootstrap {@link DataStoreTemplate}
DataStoreTemplate template = runtimeProperties.get().removeRuntimeAttribute(DataStoreTemplate.class);
if (template != null) {
// Do the initial commit and set the root tag
Ref rootTag = getGit().getRepository().getRef(GitHelpers.ROOT_TAG);
if (rootTag == null) {
getGit().commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
getGit().tag().setName(GitHelpers.ROOT_TAG).setMessage("Tag the root commit").call();
}
LOGGER.debug("Running datastore bootstrap template: " + template);
template.doWith(this, dataStore.get());
}
// Setup proxy service
GitProxyService proxyService = gitProxyService.get();
defaultProxySelector = ProxySelector.getDefault();
// authenticator disabled, until properly tested it does not affect others, as Authenticator is static in the JVM
// Authenticator.setDefault(new FabricGitLocalHostAuthenticator(proxyService));
ProxySelector fabricProxySelector = new FabricGitLocalHostProxySelector(defaultProxySelector, proxyService);
ProxySelector.setDefault(fabricProxySelector);
LOGGER.debug("Setting up FabricProxySelector: {}", fabricProxySelector);
if (gitRemoteUrl != null) {
gitListener.runRemoteUrlChanged(gitRemoteUrl);
remoteUrl = gitRemoteUrl;
} else {
gitService.get().addGitListener(gitListener);
remoteUrl = gitService.get().getRemoteUrl();
if (remoteUrl != null) {
gitListener.runRemoteUrlChanged(remoteUrl);
}
}
// Get initial versions
getInitialVersions();
// poll logic in case of remote git repo
if (gitRemoteUrl != null) {
// i need this old logic in case of remote repos
LOGGER.info("Starting to pull from remote git repository every {} millis", gitRemotePollInterval);
threadPool.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
LockHandle writeLock = aquireWriteLock();
try {
LOGGER.trace("Performing timed pull");
doPullInternal();
LOGGER.debug("Performed timed pull from external git repo");
} catch (Throwable e) {
LOGGER.debug("Error during performed timed pull/push due " + e.getMessage(), e);
LOGGER.warn("Error during performed timed pull/push due " + e.getMessage() + ". This exception is ignored.");
} finally {
writeLock.unlock();
}
}
@Override
public String toString() {
return "TimedPushTask";
}
}, 1000, gitRemotePollInterval, TimeUnit.MILLISECONDS);
}
LOGGER.info("Using ZooKeeper SharedCount to react when master git repo is changed, so we can do a git pull to the local git repo.");
counter = new SharedCount(curator.get(), ZkPath.GIT_TRIGGER.getPath(), 0);
counter.addListener(new SharedCountListener() {
@Override
public void countHasChanged(final SharedCountReader sharedCountReader, final int value) throws Exception {
Runnable task = new Runnable() {
@Override
public void run() {
doPullInternal();
}
};
if (gitRandomFetchDelay == 0) {
LOGGER.debug("Watch counter updated to " + value + ", scheduling immediate pull");
threadPool.submit(task);
} else {
int delay = RND.nextInt(gitRandomFetchDelay) + 1;
LOGGER.debug("Watch counter updated to " + value + ", scheduling pull with random delay=" + delay + "s");
threadPool.schedule(task, delay, TimeUnit.SECONDS);
}
}
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
switch(connectionState) {
case SUSPENDED:
case READ_ONLY:
case LOST:
// do nothing
break;
case CONNECTED:
case RECONNECTED:
LOGGER.info("Shared Counter (Re)connected, doing a pull");
doPullInternal();
break;
}
}
});
try {
counter.start();
} catch (KeeperException.NotReadOnlyException ex) {
// In read only mode the counter is not going to start.
// If the connection is reestablished the component will reactivate.
// We need to catch this error so that the component gets activated.
}
if (gitGcOnLoad) {
LockHandle writeLock = aquireWriteLock();
try {
GitOperation<Void> gitop = new GitOperation<Void>() {
public Void call(Git git, GitContext context) throws Exception {
long before = System.currentTimeMillis();
try {
git.gc().call();
LOGGER.debug("git gc took " + ((System.currentTimeMillis() - before)) + " ms.");
} catch (GitAPIException e) {
LOGGER.debug("git gc threw an exception!", e);
}
return null;
}
};
executeInternal(new GitContext(), null, gitop);
} finally {
writeLock.unlock();
}
}
// failing to activate the component
if (readWriteLock.isWriteLockedByCurrentThread() || readWriteLock.getWriteHoldCount() == 0) {
try {
// let's delegate to other thread in order to free MCF thread
// ENTESB-7843: there's a problem when jetty is configured with TLS and keystore location using
// profile: URI. while Jetty continues to be configured if profile:jetty.xml isn't available
// (and it isn't initially), it fails trying to access keystore via profile: URI.
// we should optimistically assume we can pull, but there's nothing wrong if we can't
// - we'll be able to pull later
threadPoolInitial.execute(new Runnable() {
@Override
public void run() {
doPullInternal(5);
}
});
} catch (IllegalStateException e) {
LOGGER.info("Another thread acquired write lock and GitDataStore can't pull from remote repository.");
}
} else {
LOGGER.info("Another thread is keeping git write lock. GitDataStore will continue activation.");
}
}
use of io.fabric8.maven.docker.util.Task in project fabric8 by jboss-fuse.
the class AetherTimeoutTest method readTimeout.
@Test
public void readTimeout() throws Exception {
// case 1: resolution fails because of timeout
// - aether uses 500ms read timeout
// - server responds with 1000ms delay
// - we interrupt resolution after 3000ms in case read timeout in socket.setSoTimeout() is set to 0
MavenConfigurationImpl mavenConfiguration = basicMavenConfiguration(500);
mavenConfiguration.setSettings(settingsWithJettyRepository());
Future<Boolean> task = pool.submit(new ResolveArtifactTask(mavenConfiguration, 1000));
try {
boolean resolved = task.get(3000, TimeUnit.MILLISECONDS);
assertFalse("Should not be resolved due to read timeout", resolved);
} catch (TimeoutException e) {
task.cancel(true);
fail("Should fail due to socket read timeout earlier, not due to future.get() timeout.");
}
// case 2: resolution doesn't fail, we're cancelling the task earlier
// - aether uses 6s read timeout
// - server responds with 3s delay
// - we interrupt resolution after 2s ensuring that Aether resolution didn't end on timeout yet
mavenConfiguration = basicMavenConfiguration(6000);
mavenConfiguration.setSettings(settingsWithJettyRepository());
task = pool.submit(new ResolveArtifactTask(mavenConfiguration, 3000));
boolean timedOut;
try {
task.get(2000, TimeUnit.MILLISECONDS);
timedOut = false;
fail("Task should not be completed yet");
} catch (TimeoutException e) {
timedOut = true;
task.cancel(true);
}
assertTrue("Resolution task should be interrupted", timedOut);
}
use of io.fabric8.maven.docker.util.Task in project fabric8 by jboss-fuse.
the class WaitForProvisionTaskTest method testProvisioningException.
@Test
public void testProvisioningException() throws Exception {
Container container = createMock(Container.class);
expect(container.getId()).andReturn("container").anyTimes();
expect(container.isAlive()).andReturn(true).anyTimes();
expect(container.isManaged()).andReturn(true).anyTimes();
expect(container.getProvisionStatus()).andReturn("success").anyTimes();
expect(container.getSshUrl()).andReturn("container:8181").anyTimes();
expect(container.getProvisionException()).andReturn(null).times(1);
expect(container.getProvisionException()).andReturn("Resolution Exception").anyTimes();
replay(container);
WaitForProvisionTask task = new WaitForProvisionTask(container, "success", 10000L);
assertFalse(task.call());
verify(container);
}
use of io.fabric8.maven.docker.util.Task in project fabric8 by jboss-fuse.
the class WaitForProvisionTaskTest method testSuccess.
@Test
public void testSuccess() throws Exception {
Container container = createMock(Container.class);
expect(container.getId()).andReturn("container").anyTimes();
expect(container.isAlive()).andReturn(false).times(6);
expect(container.isAlive()).andReturn(true).anyTimes();
expect(container.isManaged()).andReturn(true).anyTimes();
expect(container.getProvisionStatus()).andReturn("").times(3);
expect(container.getProvisionStatus()).andReturn("analyzing").times(3);
expect(container.getProvisionStatus()).andReturn("success").anyTimes();
expect(container.getSshUrl()).andReturn("container:8181").anyTimes();
expect(container.getProvisionException()).andReturn(null).anyTimes();
replay(container);
WaitForProvisionTask task = new WaitForProvisionTask(container, "success", 10000L);
assertTrue(task.call());
verify(container);
}
use of io.fabric8.maven.docker.util.Task in project fabric8 by jboss-fuse.
the class WaitForProvisionTaskTest method testProvisioningError.
@Test
public void testProvisioningError() throws Exception {
Container container = createMock(Container.class);
expect(container.getId()).andReturn("container").anyTimes();
expect(container.isAlive()).andReturn(true).anyTimes();
expect(container.isManaged()).andReturn(true).anyTimes();
expect(container.getProvisionStatus()).andReturn("").times(5);
expect(container.getProvisionStatus()).andReturn(Container.PROVISION_ERROR).anyTimes();
expect(container.getSshUrl()).andReturn("container:8181").anyTimes();
expect(container.getProvisionException()).andReturn(null).anyTimes();
replay(container);
WaitForProvisionTask task = new WaitForProvisionTask(container, "success", 10000L);
assertFalse(task.call());
verify(container);
}
Aggregations