本文整理汇总了Java中com.github.dockerjava.api.model.ContainerPort类的典型用法代码示例。如果您正苦于以下问题:Java ContainerPort类的具体用法?Java ContainerPort怎么用?Java ContainerPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContainerPort类属于com.github.dockerjava.api.model包,在下文中一共展示了ContainerPort类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DockerService
import com.github.dockerjava.api.model.ContainerPort; //导入依赖的package包/类
public DockerService(Container container, String host) {
this.host = host;
containerId = container.getId();
containerNames = Arrays.stream(container.getNames()).collect(Collectors.toList());
if (!containerNames.isEmpty()) {
name = containerNames.get(0);
} else {
name = containerId;
}
for (ContainerPort port : container.getPorts()) {
Record record = createRecord(container, port);
if (record != null) {
records.add(record);
}
}
}
示例2: createRecord
import com.github.dockerjava.api.model.ContainerPort; //导入依赖的package包/类
public Record createRecord(Container container, ContainerPort port) {
Record record = new Record()
.setName(name);
Map<String, String> labels = container.getLabels();
if (labels != null) {
for (Map.Entry<String, String> entry : labels.entrySet()) {
record.getMetadata().put(entry.getKey(), entry.getValue());
}
}
JsonArray names = new JsonArray();
containerNames.forEach(names::add);
record.getMetadata().put("docker.names", names);
record.getMetadata().put("docker.name", name);
record.getMetadata().put("docker.id", containerId);
String type = labels != null ? labels.get("service.type") : ServiceType.UNKNOWN;
if (type == null) {
type = ServiceType.UNKNOWN;
}
switch (type) {
case "http-endpoint":
return manageHttpService(record, port, labels);
default:
return manageUnknownService(record, port);
}
}
示例3: manageUnknownService
import com.github.dockerjava.api.model.ContainerPort; //导入依赖的package包/类
private Record manageUnknownService(Record record, ContainerPort port) {
if (port.getPublicPort() == null || port.getPublicPort() == 0) {
return null;
}
JsonObject location = new JsonObject();
location.put("port", port.getPublicPort());
location.put("internal-port", port.getPrivatePort());
location.put("type", port.getType());
location.put("ip", host);
return record.setLocation(location).setType(ServiceType.UNKNOWN);
}
示例4: manageHttpService
import com.github.dockerjava.api.model.ContainerPort; //导入依赖的package包/类
private static Record manageHttpService(Record record, ContainerPort port, Map<String, String> labels) {
if (port.getPublicPort() == null || port.getPublicPort() == 0) {
return null;
}
record.setType(HttpEndpoint.TYPE);
HttpLocation location = new HttpLocation()
.setHost(port.getIp())
.setPort(port.getPublicPort());
if (isTrue(labels, "ssl") || port.getPrivatePort() == 443) {
location.setSsl(true);
}
return record.setLocation(location.toJson());
}
示例5: restoreMapToPorts
import com.github.dockerjava.api.model.ContainerPort; //导入依赖的package包/类
private void restoreMapToPorts(MesosCluster cluster, Container container) {
// Restore "map ports to host" attribute
ContainerPort[] ports = container.getPorts();
if (ports != null) {
for (ContainerPort port : ports) {
if (port.getIp() != null && port.getPrivatePort() == MesosMasterConfig.MESOS_MASTER_PORT) {
cluster.setMapPortsToHost(true);
}
}
}
}
示例6: build
import com.github.dockerjava.api.model.ContainerPort; //导入依赖的package包/类
public static KieContainer build(Container container) {
if (container == null || container.getId() == null ||
container.getNames() == null || container.getNames().length == 0) {
// If container is being started just when querying it, or not id or name assigned, do not build the instance.
return null;
}
KieContainer kieContainer = new KieContainer();
kieContainer.setId(container.getId());
kieContainer.setTruncId(container.getId().substring(0, 12));
kieContainer.setImage(container.getImage());
if (container.getNames() != null) {
}
final String cName = container.getNames()[0];
kieContainer.setName(cName.substring(1, cName.length()));
kieContainer.setCommand(container.getCommand());
final long cDateTime = container.getCreated();
final Date cDate = new Date(cDateTime * 1000);
kieContainer.setCreated(cDate);
kieContainer.setStatus(container.getStatus());
final String[] _n = parseImageName(container.getImage(), null);
kieContainer.setRegistry(_n[0]);
kieContainer.setRepository(_n[1]);
kieContainer.setTag(_n[2]);
// Ports.
final ContainerPort[] ports = container.getPorts();
if (ports != null) {
final List<KieContainerPort> kiePorts = new LinkedList<KieContainerPort>();
for (final ContainerPort port : ports) {
final KieContainerPort kiePort = new KieContainerPort();
kiePort.setIp(port.getIp());
kiePort.setPrivatePort(port.getPrivatePort());
if (port.getPublicPort() != null) kiePort.setPublicPort(port.getPublicPort());
kiePort.setType(port.getType());
kiePorts.add(kiePort);
}
kieContainer.setPorts(kiePorts);
}
// Container types.
final KieImageType kieAppType = KieImageTypeManager.getKIEAppType(kieContainer.getRepository());
final KieImageType appServerType = KieImageTypeManager.getAppServerType(kieContainer.getRepository());
KieImageType dbmsType = null;
if (SharedUtils.supportsDatabase(kieAppType)) {
// Try to obtain the DBMS used in this container by its name, to avoid inspecting the container and firing new request.
dbmsType = parseDbmsType(kieContainer.getName());
if (dbmsType == null) {
// Container name does not provide the DBMS type used, try to find out it by inspecting the container.
dbmsType = KieImageTypeManager.getDBMSType(kieContainer.getRepository(), dockerService.inspect(container.getId()));
}
}
KieImageType type = null;
final List<KieImageType> types = new LinkedList<KieImageType>();
if (kieAppType != null) type = kieAppType;
if (appServerType != null && type != null) types.add(appServerType);
else type = appServerType;
if (dbmsType != null && type != null) types.add(dbmsType);
if (type == null) type = OthersType.INSTANCE;
kieContainer.setType(type);
if (!types.isEmpty()) kieContainer.setSubTypes(types);
// Application status.
if (SharedUtils.isKieApp(kieContainer)) {
KieAppStatus status = statusManager.getStatus(kieContainer.getImage());
if (status == null) {
status = statusManager.getStatus(kieContainer);
statusManager.addStatus(kieContainer.getImage(), status);
}
kieContainer.setAppStatus(status != null ? status : KieAppStatus.NOT_EVALUATED);
}
return kieContainer;
}