use of io.fabric8.insight.metrics.model.Request in project docker-maven-plugin by fabric8io.
the class AwsSigner4RequestTest method includesAuthTokenAsAwsSecurityToken.
@Test
public void includesAuthTokenAsAwsSecurityToken() {
HttpUriRequest request = RequestUtil.newGet("https://someService.us-east-1.amazonaws.com/");
request.setHeader("host", request.getURI().getHost());
String awsSecurityToken = "securityToken";
AuthConfig credentials = new AuthConfig("awsAccessKeyId", "awsSecretAccessKey", null, awsSecurityToken);
AwsSigner4 signer = new AwsSigner4("us-east-1", "someService");
signer.sign(request, credentials, new Date());
Assert.assertEquals(request.getFirstHeader("X-Amz-Security-Token").getValue(), awsSecurityToken);
}
use of io.fabric8.insight.metrics.model.Request in project docker-maven-plugin by fabric8io.
the class AwsSigner4RequestTest method testSign.
@Test
public void testSign() throws Exception {
HttpPost request = new HttpPost("https://ecr.us-east-1.amazonaws.com/");
request.setHeader("host", "ecr.us-east-1.amazonaws.com");
request.setHeader("Content-Type", "application/x-amz-json-1.1");
request.setHeader("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921.GetAuthorizationToken");
request.setEntity(new StringEntity("{\"registryIds\":[\"012345678901\"]}", StandardCharsets.UTF_8));
AwsSigner4 signer = new AwsSigner4("us-east-1", "ecr");
Date signingTime = AwsSigner4Request.TIME_FORMAT.parse("20150830T123600Z");
AwsSigner4Request sr = new AwsSigner4Request("us-east-1", "service", request, signingTime);
AuthConfig credentials = new AuthConfig("AKIDEXAMPLE", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY", null, null);
Assert.assertEquals(TASK1, signer.task1(sr));
Assert.assertEquals(TASK2, signer.task2(sr));
StringBuilder dst = new StringBuilder();
AwsSigner4.hexEncode(dst, signer.task3(sr, credentials));
Assert.assertEquals(TASK3, dst.toString());
Assert.assertEquals(TASK4, signer.task4(sr, credentials));
}
use of io.fabric8.insight.metrics.model.Request in project vertx-openshift-it by cescoffier.
the class WebSessionIT method testClusteredWebSession.
@Test
public void testClusteredWebSession() throws Exception {
HttpClient httpClient = vertx.createHttpClient();
AtomicReference<Map.Entry<String, String>> cookie = new AtomicReference<>();
int loops = 30;
for (int i = 0; i < loops; i++) {
String key = getKey(i);
String value = getValue(i);
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/web-session/" + key);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = httpClient.putAbs(url.toString());
Optional.ofNullable(cookie.get()).ifPresent(c -> request.headers().add("cookie", c.getKey() + "=" + c.getValue()));
request.handler(resp -> {
resp.cookies().stream().map(c -> c.split("=", 2)).map(split -> new SimpleImmutableEntry<>(split[0], split[1].split(";")[0])).filter(entry -> "vertx-web.session".equals(entry.getKey())).forEach(cookie::set);
latch.countDown();
}).exceptionHandler(t -> {
t.printStackTrace();
latch.countDown();
}).end(value);
latch.await(1, TimeUnit.MINUTES);
// Give some time to the replication operation
TimeUnit.SECONDS.sleep(1);
}
scaleTo(2);
// Give some time to the rebalancing process
TimeUnit.SECONDS.sleep(10);
assertNotNull("No session cookie", cookie.get());
for (int i = 0; i < loops; i++) {
String key = getKey(i);
String value = getValue(i);
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/web-session/" + key);
given().cookie(cookie.get().getKey(), cookie.get().getValue()).when().get(url).then().assertThat().statusCode(200).body(equalTo(value));
}
}
use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.
the class DeploymentAgent method handleRestartJvmFlag.
/**
* Adds support for a directive to force a restart upon the first assignment of a specific profile to a container.
* It creates an entry in zk so that a subsequent modification to the same profile, will not trigger a jvm restart.
* The behavior is useful for situation when a profile provision .jars in lib/ folder, that are picked up only at
* jvm boot time.
*
* @param profile
* @param restart
* @return
*/
protected boolean handleRestartJvmFlag(Profile profile, AtomicBoolean restart) {
boolean result = false;
List<String> profilesRequiringRestart = new ArrayList<>();
ServiceReference<CuratorFramework> curatorServiceReference = systemBundleContext.getServiceReference(CuratorFramework.class);
ServiceReference<FabricService> fabricServiceReference = systemBundleContext.getServiceReference(FabricService.class);
if (curatorServiceReference != null && fabricServiceReference != null) {
CuratorFramework curator = systemBundleContext.getService(curatorServiceReference);
FabricService fs = systemBundleContext.getService(fabricServiceReference);
String currentContainerName = fs.getCurrentContainerName();
List<String> activeProfiles = fs.getCurrentContainer().getProfileIds();
// check for jvm restart requests
Map<String, String> agentProperties = profile.getConfiguration("io.fabric8.agent");
Map<String, String> jvmRestartEntries = new HashMap<>();
for (String key : agentProperties.keySet()) {
if (key.startsWith("io.fabric8.agent.forceOneTimeJVMRestart")) {
jvmRestartEntries.put(key, agentProperties.get(key));
LOGGER.info("Found a profile carrying a one-time JVM restart request: {}", key);
}
}
// clean old entries
String basePath = ZkPath.CONTAINER_PROVISION_RESTART.getPath(currentContainerName);
try {
if (ZooKeeperUtils.exists(curator, basePath) != null) {
List<String> zkPaths = ZooKeeperUtils.getAllChildren(curator, ZkPath.CONTAINER_PROVISION_RESTART.getPath(currentContainerName));
for (String zkPath : zkPaths) {
String[] split = zkPath.split("/");
String prof = split[split.length - 1];
if (!activeProfiles.contains(prof)) {
LOGGER.info("Deleting old JVM restart request status: {}", zkPath);
ZooKeeperUtils.delete(curator, zkPath);
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to check ZK connection", e);
}
for (String key : jvmRestartEntries.keySet()) {
String[] split = key.split("\\.");
String profileForcingRestart = split[split.length - 1];
try {
String zkPath = ZkPath.CONTAINER_PROVISION_RESTART_PROFILES.getPath(currentContainerName, profileForcingRestart);
Stat exists = exists(curator, zkPath);
if (exists == null) {
ZooKeeperUtils.create(curator, zkPath);
profilesRequiringRestart.add(profileForcingRestart);
result = true;
}
} catch (Exception e) {
LOGGER.error("Unable to check ZK connection", e);
}
}
}
if (result) {
System.setProperty("karaf.restart.jvm", "true");
restart.set(true);
LOGGER.warn("Profiles {} scheduled a JVM restart request. Automated JVM restart support is not universally available. If your jvm doesn't support it you are required to manually restart the container that has just been assigned the profile.", profilesRequiringRestart);
try {
bundleContext.getBundle(0).stop();
} catch (BundleException e) {
LOGGER.error("Error when forcing a JVM restart", e);
}
}
return result;
}
use of io.fabric8.insight.metrics.model.Request in project fabric8 by jboss-fuse.
the class FabricGitSummaryAction method afterEachContainer.
@Override
protected void afterEachContainer(Collection<String> names) {
System.out.printf("Scheduled git-summary command to %d containers. Awaiting response(s).\n", names.size());
final CountDownLatch latch = new CountDownLatch(requests.size() + (masterRequest == null ? 0 : 1));
Thread waiter = null;
try {
waiter = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
String currentContainer = null;
try {
// master request
if (masterRequest != null && masterResult == null) {
currentContainer = master;
List<JMXResult> results = fetchResponses(master);
for (JMXResult result : results) {
if (result.getCorrelationId().equals(masterRequest.getId())) {
masterResult = result;
latch.countDown();
break;
}
}
}
// requests for containers
for (Map.Entry<String, JMXRequest> req : requests.entrySet()) {
currentContainer = req.getKey();
List<JMXResult> containerResults = fetchResponses(currentContainer);
for (JMXResult result : containerResults) {
if (result.getCorrelationId().equals(req.getValue().getId())) {
results.put(currentContainer, result);
latch.countDown();
break;
}
}
}
if ((masterRequest == null || masterResult != null) && results.size() == requests.size()) {
break;
} else {
// active waiting - so no need for ZK watchers, etc...
Thread.sleep(1000);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
} catch (Exception e) {
System.err.println("Problem occurred while fetching response from " + currentContainer + " container: " + e.getMessage());
// active waiting - so no need for ZK watchers, etc...
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
}
}
}
});
waiter.start();
boolean finished = latch.await(timeout, TimeUnit.MILLISECONDS);
if (!finished) {
waiter.interrupt();
System.out.println("Timeout waiting for git-summary response");
return;
}
// before printing summary, let's check if there are out of sync containers
Map<String, String> centralGitRepo = new HashMap<>();
Set<String> outOfSyncContainers = new TreeSet<>();
if (masterResult != null) {
for (GitVersion version : ((GitVersions) masterResult.getResponse()).getVersions()) {
centralGitRepo.put(version.getVersion(), version.getSha1());
}
for (String containerName : results.keySet()) {
List<GitVersion> localRepo = ((GitVersions) results.get(containerName).getResponse()).getVersions();
for (GitVersion version : localRepo) {
String ref = centralGitRepo.get(version.getVersion());
if (ref == null) {
// local container knows about version, which is not tracked in central repo
outOfSyncContainers.add(containerName);
} else if (!ref.equals(version.getSha1())) {
// version not in sync
outOfSyncContainers.add(containerName);
}
}
if (localRepo.size() != centralGitRepo.size()) {
// extra or not-in-sync versions handled, so this must mean some central version is not
// available locally
outOfSyncContainers.add(containerName);
}
}
if (outOfSyncContainers.size() > 0) {
System.out.println();
System.out.println("Containers that require synchronization: " + outOfSyncContainers);
System.out.println("Please use \"fabric:git-synchronize\" command");
}
} else {
System.out.println();
System.out.println("Can't determine synchronization status of containers - no master Git repository detected");
}
// now summary time
if (masterResult != null) {
System.out.println();
printVersions("=== Summary for master Git repository (container: " + master + ") ===", ((GitVersions) masterResult.getResponse()).getVersions());
}
System.out.println();
for (String containerName : results.keySet()) {
printVersions("=== Summary for local Git repository (container: " + containerName + ") ===", ((GitVersions) results.get(containerName).getResponse()).getVersions());
System.out.println();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
waiter.interrupt();
System.out.println("Interrupted waiting for git-summary response");
}
}
Aggregations