use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.
the class Manager method init.
public void init() throws Exception {
// Create client and server
this.client = new ClientInvokerImpl(queue, timeout, serializationStrategies);
this.server = new ServerInvokerImpl(uri, queue, serializationStrategies);
this.client.start();
this.server.start();
// ZooKeeper tracking
try {
create(curator, DOSGI_REGISTRY, CreateMode.PERSISTENT);
} catch (KeeperException.NodeExistsException e) {
// The node already exists, that's fine
}
this.tree = new TreeCacheExtended(curator, DOSGI_REGISTRY, true);
this.tree.getListenable().addListener(this);
this.tree.start();
// UUID
this.uuid = Utils.getUUID(this.bundleContext);
// Service listener filter
String filter = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)";
// Initialization
this.bundleContext.addServiceListener(this, filter);
// Service registration
this.registration = this.bundleContext.registerService(new String[] { ListenerHook.class.getName(), EventHook.class.getName(), FindHook.class.getName() }, this, null);
// Check existing services
ServiceReference[] references = this.bundleContext.getServiceReferences((String) null, filter);
if (references != null) {
for (ServiceReference reference : references) {
exportService(reference);
}
}
}
use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.
the class FabricManager method registerMBeanServer.
public void registerMBeanServer(ShutdownTracker shutdownTracker, MBeanServer mbeanServer) {
try {
ObjectName name = getObjectName();
if (!mbeanServer.isRegistered(name)) {
StandardMBean mbean = new StandardMBean(this, FabricManagerMBean.class);
mbeanServer.registerMBean(mbean, name);
}
} catch (Exception e) {
LOG.warn("An error occurred during mbean server registration: " + e, e);
}
}
use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.
the class JoinTest method testJoin.
@Test
public void testJoin() throws Exception {
System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
BundleContext moduleContext = ServiceLocator.getSystemContext();
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
AdminService adminService = ServiceLocator.awaitService(AdminService.class);
String version = System.getProperty("fabric.version");
System.err.println(CommandSupport.executeCommand("admin:create -o '-server -Xmx1536M -Dcom.sun.management.jmxremote -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -Dpatching.disabled=true -Djava.security.egd=file:/dev/./urandom' --featureURL mvn:io.fabric8/fabric8-karaf/" + version + "/xml/features --feature fabric-git --feature fabric-agent --feature fabric-boot-commands smoke_child_d"));
try {
System.err.println(CommandSupport.executeCommand("admin:start smoke_child_d"));
ProvisionSupport.instanceStarted(Arrays.asList("smoke_child_d"), ProvisionSupport.PROVISION_TIMEOUT);
System.err.println(CommandSupport.executeCommand("admin:list"));
String joinCommand = "fabric:join -f --zookeeper-password " + fabricService.getZookeeperPassword() + " " + fabricService.getZookeeperUrl();
String response = "";
for (int i = 0; i < 10 && !response.contains("true"); i++) {
response = CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("smoke_child_d").getSshPort() + " localhost " + WAIT_FOR_JOIN_SERVICE);
Thread.sleep(1000);
}
System.err.println(CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("smoke_child_d").getSshPort() + " localhost " + joinCommand));
ProvisionSupport.containersExist(Arrays.asList("smoke_child_d"), ProvisionSupport.PROVISION_TIMEOUT);
Container childD = fabricService.getContainer("smoke_child_d");
System.err.println(CommandSupport.executeCommand("fabric:container-list"));
ProvisionSupport.containerStatus(Arrays.asList(childD), "success", ProvisionSupport.PROVISION_TIMEOUT);
System.err.println(CommandSupport.executeCommand("fabric:container-list"));
} finally {
System.err.println(CommandSupport.executeCommand("admin:stop smoke_child_d"));
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.insight.metrics.model.Server in project halyard by spinnaker.
the class KubernetesV1DistributedService method getRunningServiceDetails.
@Override
default RunningServiceDetails getRunningServiceDetails(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails res = new RunningServiceDetails();
KubernetesClient client = KubernetesV1ProviderUtils.getClient(details);
String name = getServiceName();
String namespace = getNamespace(settings);
RunningServiceDetails.LoadBalancer lb = new RunningServiceDetails.LoadBalancer();
lb.setExists(client.services().inNamespace(namespace).withName(name).get() != null);
res.setLoadBalancer(lb);
List<Pod> pods = client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "true").list().getItems();
pods.addAll(client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "false").list().getItems());
Map<Integer, List<Instance>> instances = res.getInstances();
for (Pod pod : pods) {
String podName = pod.getMetadata().getName();
String serverGroupName = podName.substring(0, podName.lastIndexOf("-"));
Names parsedName = Names.parseName(serverGroupName);
Integer version = parsedName.getSequence();
if (version == null) {
throw new IllegalStateException("Server group for service " + getServiceName() + " has unknown sequence (" + serverGroupName + ")");
}
String location = pod.getMetadata().getNamespace();
String id = pod.getMetadata().getName();
Instance instance = new Instance().setId(id).setLocation(location);
List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
if (!containerStatuses.isEmpty() && containerStatuses.stream().allMatch(ContainerStatus::getReady)) {
instance.setHealthy(true);
}
if (!containerStatuses.isEmpty() && containerStatuses.stream().allMatch(s -> s.getState().getRunning() != null && s.getState().getTerminated() == null)) {
instance.setRunning(true);
}
List<Instance> knownInstances = instances.getOrDefault(version, new ArrayList<>());
knownInstances.add(instance);
instances.put(version, knownInstances);
}
List<ReplicaSet> replicaSets = client.extensions().replicaSets().inNamespace(settings.getLocation()).list().getItems();
for (ReplicaSet rs : replicaSets) {
String rsName = rs.getMetadata().getName();
Names parsedRsName = Names.parseName(rsName);
if (!parsedRsName.getCluster().equals(getServiceName())) {
continue;
}
instances.computeIfAbsent(parsedRsName.getSequence(), i -> new ArrayList<>());
}
return res;
}
use of io.fabric8.insight.metrics.model.Server in project curiostack by curioswitch.
the class CreateClientCertTask method exec.
@TaskAction
public void exec() {
ImmutableClusterExtension cluster = getProject().getExtensions().getByType(ClusterExtension.class);
String commonName = (String) getProject().getRootProject().findProperty("commonName");
checkNotNull(commonName, "-PcommonName must be set");
final KeyPairGenerator keygen;
try {
keygen = KeyPairGenerator.getInstance("ECDSA", BouncyCastleProvider.PROVIDER_NAME);
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
throw new IllegalStateException("Could not find RSA, can't happen.", e);
}
keygen.initialize(256, new SecureRandom());
KeyPair keyPair = keygen.generateKeyPair();
PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(new X500Principal("CN=" + commonName), keyPair.getPublic());
final ContentSigner signer;
try {
signer = new JcaContentSignerBuilder("SHA256withECDSA").build(keyPair.getPrivate());
} catch (OperatorCreationException e) {
throw new IllegalStateException("Could not find signer, can't happen.", e);
}
PKCS10CertificationRequest csr = p10Builder.build(signer);
StringWriter csrWriter = new StringWriter();
try (JcaPEMWriter pemWriter = new JcaPEMWriter(csrWriter)) {
pemWriter.writeObject(csr);
} catch (IOException e) {
throw new IllegalStateException("Could not encode csr, can't happen.", e);
}
String encodedCsr = Base64.getEncoder().encodeToString(csrWriter.toString().getBytes(StandardCharsets.UTF_8));
String csrName = cluster.namespace() + "." + commonName + ".client.crt";
Map<Object, Object> csrApiRequest = ImmutableMap.of("apiVersion", "certificates.k8s.io/v1beta1", "kind", "CertificateSigningRequest", "metadata", ImmutableMap.of("name", csrName), "spec", ImmutableMap.of("request", encodedCsr, "usages", ImmutableList.of("digital signature", "key encipherment", "server auth", "client auth")));
final byte[] encodedApiRequest;
try {
encodedApiRequest = OBJECT_MAPPER.writeValueAsBytes(csrApiRequest);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Could not encode yaml", e);
}
ImmutableGcloudExtension config = getProject().getRootProject().getExtensions().getByType(GcloudExtension.class);
String command = config.download() ? new File(config.platformConfig().gcloudBinDir(), "kubectl").getAbsolutePath() : "kubectl";
getProject().exec(exec -> {
exec.executable(command);
exec.args("create", "-f", "-");
exec.setStandardInput(new ByteArrayInputStream(encodedApiRequest));
});
getProject().exec(exec -> {
exec.executable(command);
exec.args("certificate", "approve", csrName);
});
// Need to wait a bit for certificate to propagate before fetching.
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
ByteArrayOutputStream certStream = new ByteArrayOutputStream();
getProject().exec(exec -> {
exec.executable(command);
exec.args("get", "csr", csrName, "-o", "jsonpath={.status.certificate}");
exec.setStandardOutput(certStream);
});
String certificate = new String(Base64.getDecoder().decode(certStream.toByteArray()), StandardCharsets.UTF_8);
final JcaPKCS8Generator keyGenerator;
final PemObject keyObject;
try {
keyGenerator = new JcaPKCS8Generator(keyPair.getPrivate(), null);
keyObject = keyGenerator.generate();
} catch (PemGenerationException e) {
throw new IllegalStateException("Could not encode to pkcs8.", e);
}
StringWriter keyWriter = new StringWriter();
try (JcaPEMWriter pemWriter = new JcaPEMWriter(keyWriter)) {
pemWriter.writeObject(keyObject);
} catch (IOException e) {
throw new IllegalStateException("Could not encode csr, can't happen.", e);
}
String key = keyWriter.toString();
KubernetesClient client = new DefaultKubernetesClient();
Secret certificateSecret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(commonName + "-client-tls").withNamespace(cluster.namespace()).build()).withType("Opaque").withData(ImmutableMap.of("client.crt", Base64.getEncoder().encodeToString(certificate.getBytes(StandardCharsets.UTF_8)), "client-key.pem", Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8)))).build();
client.resource(certificateSecret).createOrReplace();
}
Aggregations