use of io.fabric8.insight.metrics.model.Server in project camel by apache.
the class KubernetesReplicationControllersConsumerTest method createAndDeleteReplicationController.
@Test
public void createAndDeleteReplicationController() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
mockResultEndpoint.expectedHeaderValuesReceivedInAnyOrder(KubernetesConstants.KUBERNETES_EVENT_ACTION, "ADDED", "DELETED", "MODIFIED", "MODIFIED", "MODIFIED");
Exchange ex = template.request("direct:createReplicationController", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, labels);
ReplicationControllerSpec rcSpec = new ReplicationControllerSpec();
rcSpec.setReplicas(2);
PodTemplateSpecBuilder builder = new PodTemplateSpecBuilder();
PodTemplateSpec t = builder.withNewMetadata().withName("nginx-template").addToLabels("server", "nginx").endMetadata().withNewSpec().addNewContainer().withName("wildfly").withImage("jboss/wildfly").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().build();
rcSpec.setTemplate(t);
Map<String, String> selectorMap = new HashMap<String, String>();
selectorMap.put("server", "nginx");
rcSpec.setSelector(selectorMap);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, rcSpec);
}
});
ReplicationController rc = ex.getOut().getBody(ReplicationController.class);
assertEquals(rc.getMetadata().getName(), "test");
ex = template.request("direct:deleteReplicationController", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, "test");
}
});
boolean rcDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(rcDeleted);
Thread.sleep(3000);
mockResultEndpoint.assertIsSatisfied();
}
use of io.fabric8.insight.metrics.model.Server in project syndesis-qe by syndesisio.
the class AmqTemplate method deploy.
public static void deploy() {
Template template = null;
try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-amq.yml")) {
template = OpenShiftUtils.client().templates().load(is).get();
} catch (IOException ex) {
throw new IllegalArgumentException("Unable to read template ", ex);
}
Map<String, String> templateParams = new HashMap<>();
templateParams.put("MQ_USERNAME", "amq");
templateParams.put("MQ_PASSWORD", "topSecret");
// try to clean previous broker
cleanUp();
OpenShiftUtils.client().templates().withName("syndesis-amq").delete();
KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
OpenShiftUtils.getInstance().createResources(processedTemplate);
try {
OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.isAPodReady("application", "broker"));
} catch (InterruptedException | TimeoutException e) {
log.error("Wait for syndesis-server failed ", e);
}
// this is not part of deployment, but let's have it the same method:
AmqTemplate.addAccounts();
}
use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.
the class ZooKeeperUtils method generateContainerToken.
public static String generateContainerToken(RuntimeProperties sysprops, CuratorFramework curator) {
String container = sysprops.getRuntimeIdentity();
long time = System.currentTimeMillis();
String password = null;
try {
if (time - lastTokenGenerationTime < 60 * 1000) {
try {
password = getStringData(curator, CONTAINERS_NODE + "/" + container);
} catch (KeeperException.NoNodeException ex) {
// Node hasn't been created yet. It's safe to ignore.
}
}
if (password == null) {
password = generatePassword();
setData(curator, CONTAINERS_NODE + "/" + container, password);
lastTokenGenerationTime = time;
}
} catch (KeeperException.NotReadOnlyException e) {
throw new FabricException("ZooKeeper server is partitioned. Currently working in read-only mode!");
} catch (RuntimeException rte) {
throw rte;
} catch (Exception ex) {
throw new IllegalStateException("Cannot generate container token", ex);
}
return password;
}
use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.
the class ProfileCopyAction method doExecute.
@Override
protected Object doExecute() throws Exception {
// but validate the target name
try {
FabricValidations.validateProfileName(target);
} catch (IllegalArgumentException e) {
// we do not want exception in the server log, so print the error message to the console
System.out.println(e.getMessage());
return 1;
}
Version version = versionParam != null ? profileService.getRequiredVersion(versionParam) : fabricService.getRequiredDefaultVersion();
String versionId = version.getId();
if (!version.hasProfile(source)) {
System.out.println("Source profile " + source + " not found.");
return 1;
} else if (version.hasProfile(target)) {
if (!force) {
System.out.println("Target profile " + target + " already exists. Use --force if you want to overwrite.");
return null;
}
}
Profiles.copyProfile(fabricService, versionId, source, target, force);
return null;
}
use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.
the class ProfileCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
try {
FabricValidations.validateProfileName(profileId);
} catch (IllegalArgumentException e) {
// we do not want exception in the server log, so print the error message to the console
System.out.println(e.getMessage());
return 1;
}
if (versionId != null) {
profileService.getRequiredVersion(versionId);
} else {
versionId = fabricService.getDefaultVersionId();
}
// we can only use existing parent profiles
Profile[] parents = FabricCommand.getExistingProfiles(fabricService, versionId, this.parents);
ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
for (Profile parent : parents) {
builder.addParent(parent.getId());
}
profileService.createProfile(builder.getProfile());
return null;
}
Aggregations