use of io.fabric8.patch.Service in project docker-maven-plugin by fabric8io.
the class VolumeServiceTest method testCreateVolumeConfig.
@Test
public void testCreateVolumeConfig() throws Exception {
final VolumeConfiguration config = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
new Expectations() {
{
// Use a 'delegate' to verify the argument given directly. No need
// for an 'intermediate' return method in the service just to check this.
docker.createVolume(with(new Delegate<VolumeCreateConfig>() {
void check(VolumeCreateConfig vcc) {
assertThat(vcc.getName(), is("testVolume"));
JSONObject vccJson = (JSONObject) JSONParser.parseJSON(vcc.toJson());
assertEquals(vccJson.get("Driver"), "test");
}
}));
result = "testVolume";
}
};
String volume = new VolumeService(docker).createVolume(config);
assertEquals(volume, "testVolume");
}
use of io.fabric8.patch.Service in project kie-wb-common by kiegroup.
the class OpenShiftClient method getDeploymentConfig.
private DeploymentConfig getDeploymentConfig(KubernetesList list, String svcName) {
if (list != null) {
List<HasMetadata> items = list.getItems();
String dcName = null;
for (HasMetadata item : items) {
if (item instanceof Service && item.getMetadata().getName().equals(svcName)) {
Map<String, String> selector = ((Service) item).getSpec().getSelector();
dcName = selector.get("deploymentconfig");
if (dcName == null) {
dcName = selector.get("deploymentConfig");
}
break;
}
}
if (dcName != null) {
for (HasMetadata item : items) {
if (item instanceof DeploymentConfig && item.getMetadata().getName().equals(dcName)) {
return (DeploymentConfig) item;
}
}
}
}
return null;
}
use of io.fabric8.patch.Service in project kie-wb-common by kiegroup.
the class OpenShiftClient method setReplicas.
private void setReplicas(String id, int replicas) throws InterruptedException {
OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
String prjName = runtimeId.project();
String svcName = runtimeId.service();
Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> dcr = getDeploymentConfigResource(service);
if (dcr != null) {
DeploymentConfig dc = dcr.get();
dc.getSpec().setReplicas(replicas);
dcr.replace(dc);
dcr.waitUntilReady(buildTimeout, TimeUnit.MILLISECONDS);
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class ClusterListAction method printCluster.
protected void printCluster(String dir, PrintStream out) throws Exception {
// do we have any clusters at all?
if (exists(getCurator(), dir) == null) {
return;
}
List<String> children = getAllChildren(getCurator(), dir);
Map<String, Map<String, ClusterNode>> clusters = new TreeMap<String, Map<String, ClusterNode>>();
for (String child : children) {
byte[] data = getCurator().getData().forPath(child);
if (data != null && data.length > 0) {
String text = new String(data).trim();
if (!text.isEmpty()) {
String clusterName = getClusterName(dir, child);
Map<String, ClusterNode> cluster = clusters.get(clusterName);
if (cluster == null) {
cluster = new TreeMap<String, ClusterNode>();
clusters.put(clusterName, cluster);
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = null;
try {
map = mapper.readValue(data, HashMap.class);
} catch (JsonParseException e) {
log.error("Error parsing JSON string: {}", text);
throw e;
}
ClusterNode node = null;
Object id = value(map, "id", "container");
if (id != null) {
Object agent = value(map, "container", "agent");
List services = (List) value(map, "services");
node = cluster.get(id);
if (node == null) {
node = new ClusterNode();
cluster.put(id.toString(), node);
}
if (services != null) {
if (!services.isEmpty()) {
for (Object service : services) {
node.services.add(getSubstitutedData(getCurator(), service.toString()));
}
node.masters.add(agent);
} else {
node.slaves.add(agent);
}
} else {
Object started = value(map, "started");
if (started == Boolean.TRUE) {
node.masters.add(agent);
} else {
node.slaves.add(agent);
}
}
}
}
}
}
TablePrinter table = new TablePrinter();
table.columns("cluster", "masters", "slaves", "services");
for (String clusterName : clusters.keySet()) {
Map<String, ClusterNode> nodes = clusters.get(clusterName);
table.row(clusterName, "", "", "", "");
for (String nodeName : nodes.keySet()) {
ClusterNode node = nodes.get(nodeName);
table.row(" " + nodeName, printList(node.masters), printList(node.slaves), printList(node.services));
}
}
table.print();
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class Deployer method getBundlesToStart.
protected List<Bundle> getBundlesToStart(Collection<Bundle> bundles, Bundle serviceBundle) {
// Restart the features service last, regardless of any other consideration
// so that we don't end up with the service trying to do stuff before we're done
boolean restart = false;
SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<>();
for (Bundle bundle : bundles) {
if (bundle == serviceBundle) {
restart = true;
} else {
int sl = bundle.adapt(BundleStartLevel.class).getStartLevel();
addToMapSet(bundlesPerStartLevel, sl, bundle);
}
}
if (bundlesPerStartLevel.isEmpty()) {
bundles = Collections.emptyList();
} else {
bundles = bundlesPerStartLevel.remove(bundlesPerStartLevel.firstKey());
}
List<BundleRevision> revs = new ArrayList<>();
for (Bundle bundle : bundles) {
revs.add(bundle.adapt(BundleRevision.class));
}
List<Bundle> sorted = new ArrayList<>();
for (BundleRevision rev : RequirementSort.sort(revs)) {
sorted.add(rev.getBundle());
}
if (sorted.isEmpty() && restart) {
sorted.add(serviceBundle);
}
return sorted;
}
Aggregations