use of oracle.kubernetes.weblogic.domain.v1.DomainSpec in project weblogic-kubernetes-operator by oracle.
the class Main method doCheckAndCreateDomainPresence.
private static void doCheckAndCreateDomainPresence(Domain dom, boolean explicitRecheck, boolean explicitRestartAdmin, List<String> explicitRestartServers, List<String> explicitRestartClusters) {
LOGGER.entering();
boolean hasExplicitRestarts = explicitRestartAdmin || explicitRestartServers != null || explicitRestartClusters != null;
DomainSpec spec = dom.getSpec();
normalizeDomainSpec(spec);
String domainUID = spec.getDomainUID();
DomainPresenceInfo created = new DomainPresenceInfo(dom);
DomainPresenceInfo info = domains.putIfAbsent(domainUID, created);
if (info == null) {
info = created;
} else {
// Has the spec actually changed? We will get watch events for status updates
Domain current = info.getDomain();
if (current != null) {
if (!explicitRecheck && !hasExplicitRestarts && spec.equals(current.getSpec())) {
// nothing in the spec has changed
LOGGER.fine(MessageKeys.NOT_STARTING_DOMAINUID_THREAD, domainUID);
return;
}
}
info.setDomain(dom);
}
String ns = dom.getMetadata().getNamespace();
if (initialized.getOrDefault(ns, Boolean.FALSE) && !stopping.get()) {
LOGGER.info(MessageKeys.PROCESSING_DOMAIN, domainUID);
Step managedServerStrategy = bringManagedServersUp(DomainStatusUpdater.createEndProgressingStep(null));
Step adminServerStrategy = bringAdminServerUp(connectToAdminAndInspectDomain(managedServerStrategy));
Step strategy = DomainStatusUpdater.createProgressingStep(DomainStatusUpdater.INSPECTING_DOMAIN_PROGRESS_REASON, true, new DomainPrescenceStep(adminServerStrategy, managedServerStrategy));
Packet p = new Packet();
PodWatcher pw = podWatchers.get(ns);
p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version, pw));
p.put(ProcessingConstants.PRINCIPAL, principal);
if (explicitRestartAdmin) {
p.put(ProcessingConstants.EXPLICIT_RESTART_ADMIN, Boolean.TRUE);
}
p.put(ProcessingConstants.EXPLICIT_RESTART_SERVERS, explicitRestartServers);
p.put(ProcessingConstants.EXPLICIT_RESTART_CLUSTERS, explicitRestartClusters);
if (explicitRestartAdmin) {
LOGGER.info(MessageKeys.RESTART_ADMIN_STARTING, domainUID);
}
if (explicitRestartServers != null) {
LOGGER.info(MessageKeys.RESTART_SERVERS_STARTING, domainUID, explicitRestartServers);
}
if (explicitRestartClusters != null) {
LOGGER.info(MessageKeys.ROLLING_CLUSTERS_STARTING, domainUID, explicitRestartClusters);
}
domainUpdaters.startFiber(domainUID, strategy, p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
if (explicitRestartAdmin) {
LOGGER.info(MessageKeys.RESTART_ADMIN_COMPLETE, domainUID);
}
if (explicitRestartServers != null) {
LOGGER.info(MessageKeys.RESTART_SERVERS_COMPLETE, domainUID, explicitRestartServers);
}
if (explicitRestartClusters != null) {
LOGGER.info(MessageKeys.ROLLING_CLUSTERS_COMPLETE, domainUID, explicitRestartClusters);
}
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
domainUpdaters.startFiberIfLastFiberMatches(domainUID, Fiber.getCurrentIfSet(), DomainStatusUpdater.createFailedStep(throwable, null), p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
// no-op
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
}
});
// TODO: consider retrying domain update after a delay
}
});
scheduleDomainStatusUpdating(info);
}
LOGGER.exiting();
}
use of oracle.kubernetes.weblogic.domain.v1.DomainSpec in project weblogic-kubernetes-operator by oracle.
the class WlsDomainConfig method updateDomainSpecAsNeeded.
/**
* Update the provided k8s domain spec to be consistent with the configuration of the WLS domain.
* The method also logs warning if inconsistent WLS configurations are found that cannot be fixed by updating
* the provided Domain spec.
* It is the responsibility of the caller to persist the changes to DomainSpec to kubernetes.
*
* @param domainSpec The DomainSpec to be validated against the WLS configuration
* @return true if the DomainSpec has been updated, false otherwise
*/
public boolean updateDomainSpecAsNeeded(DomainSpec domainSpec) {
LOGGER.entering();
boolean updated = false;
List<ClusterStartup> clusterStartupList = domainSpec.getClusterStartup();
// check each ClusterStartup if specified in the DomainSpec
if (clusterStartupList != null) {
for (ClusterStartup clusterStartup : clusterStartupList) {
String clusterName = clusterStartup.getClusterName();
if (clusterName != null) {
WlsClusterConfig wlsClusterConfig = getClusterConfig(clusterName);
updated |= wlsClusterConfig.validateClusterStartup(clusterStartup);
}
}
}
// validate replicas in DomainSpec if spcified
if (domainSpec.getReplicas() != null) {
Collection<WlsClusterConfig> clusterConfigs = getClusterConfigs().values();
// WLS domain contains only one cluster
if (clusterConfigs != null && clusterConfigs.size() == 1) {
for (WlsClusterConfig wlsClusterConfig : clusterConfigs) {
wlsClusterConfig.validateReplicas(domainSpec.getReplicas(), "domainSpec");
}
} else {
// log info message if replicas is specified but number of WLS clusters in domain is not 1
LOGGER.info(MessageKeys.DOMAIN_REPLICAS_IGNORED);
}
}
LOGGER.exiting(updated);
return updated;
}
use of oracle.kubernetes.weblogic.domain.v1.DomainSpec in project weblogic-kubernetes-operator by oracle.
the class IngressHelperTest method setUp.
@Before
public void setUp() throws ApiException {
// make sure test bed is clean
tearDown();
// Create domain
Domain domain = new Domain();
V1ObjectMeta metadata = new V1ObjectMeta();
metadata.setName("domianIngressHelperTest");
metadata.setNamespace(namespace);
domain.setMetadata(metadata);
DomainSpec spec = new DomainSpec();
spec.setDomainName("base_domain");
spec.setDomainUID(domainUID);
domain.setSpec(spec);
info = new DomainPresenceInfo(domain);
// Create scan
WlsDomainConfig scan = new WlsDomainConfig();
WlsServerConfig server1Scan = new WlsServerConfig(server1Name, server1Port, server1Name, null);
WlsServerConfig server2Scan = new WlsServerConfig(server2Name, server2Port, server2Name, null);
scan.getServerConfigs().put(server1Name, server1Scan);
scan.getServerConfigs().put(server2Name, server2Scan);
WlsClusterConfig cluster1Scan = new WlsClusterConfig(clusterName);
cluster1Scan.getServerConfigs().add(server1Scan);
cluster1Scan.getServerConfigs().add(server2Scan);
scan.getClusterConfigs().put(clusterName, cluster1Scan);
info.setScan(scan);
ServerKubernetesObjects sko = new ServerKubernetesObjects();
V1Service service = new V1Service();
V1ObjectMeta sm = new V1ObjectMeta();
sm.setName(service1Name);
sm.setNamespace(namespace);
service.setMetadata(sm);
V1ServiceSpec ss = new V1ServiceSpec();
V1ServicePort port = new V1ServicePort();
port.setPort(server1Port);
ss.addPortsItem(port);
service.setSpec(ss);
sko.getService().set(service);
info.getServers().put(server1Name, sko);
sko = new ServerKubernetesObjects();
service = new V1Service();
sm = new V1ObjectMeta();
sm.setName(service2Name);
sm.setNamespace(namespace);
service.setMetadata(sm);
ss = new V1ServiceSpec();
port = new V1ServicePort();
port.setPort(server2Port);
ss.addPortsItem(port);
service.setSpec(ss);
sko.getService().set(service);
info.getServers().put(server2Name, sko);
engine = new Engine("IngressHelperTest");
}
use of oracle.kubernetes.weblogic.domain.v1.DomainSpec in project weblogic-kubernetes-operator by oracle.
the class ServiceHelperTest method createReadListUpdate.
@Test
public void createReadListUpdate() throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
// Domain
Domain dom = new Domain();
V1ObjectMeta metadata = new V1ObjectMeta();
metadata.setResourceVersion("12345");
metadata.setNamespace("tests");
dom.setMetadata(metadata);
DomainSpec spec = new DomainSpec();
spec.setDomainUID("domain-uid");
spec.setDomainName("base_domain");
dom.setSpec(spec);
// Create a new service.
System.out.println("Creating service");
Step s = ServiceHelper.createForServerStep(null);
Engine e = new Engine("ServiceHelperTest");
Packet p = new Packet();
DomainPresenceInfo info = new DomainPresenceInfo(dom);
p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info));
p.put(ProcessingConstants.SERVER_NAME, "admin");
p.put(ProcessingConstants.PORT, Integer.valueOf(7001));
Fiber f = e.createFiber();
f.start(s, p, null);
f.get();
// Read the service we just created.
System.out.println("Reading service");
V1Service service = factory.create().readService("domain-uid-admin", "tests");
checkService(service, false);
// Get a list of services.
System.out.println("Listing services");
V1ServiceList serviceList = factory.create().listService("tests");
boolean serviceFound = false;
for (V1Service item : serviceList.getItems()) {
if (item.getMetadata().getName().equals("domain-uid-admin")) {
serviceFound = true;
break;
}
}
Assert.assertTrue("Expected service domain-uid-admin not found in list", serviceFound);
// Add a second selector to this service.
Map<String, String> selector = service.getSpec().getSelector();
selector.put("domain", "domain-uid");
service.getSpec().setSelector(selector);
// TODO: uncomment out when bug calling replace service is fixed.
// System.out.println("Replacing service");
// service = serviceHelper.replace("domain-uid-admin", service);
// checkService(service, true);
}
use of oracle.kubernetes.weblogic.domain.v1.DomainSpec in project weblogic-kubernetes-operator by oracle.
the class WlsDomainConfigTest method verifyUpdateDomainSpecWarnsIfNoServersInClusterStartupCluster.
@Test
public void verifyUpdateDomainSpecWarnsIfNoServersInClusterStartupCluster() throws Exception {
WlsDomainConfig wlsDomainConfig = new WlsDomainConfig();
DomainSpec domainSpec = new DomainSpec().withClusterStartup(Arrays.asList(new ClusterStartup().withClusterName("noSuchCluster")));
TestUtil.LogHandlerImpl handler = null;
WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig("noSuchCluster");
try {
handler = TestUtil.setupLogHandler(wlsClusterConfig);
wlsDomainConfig.updateDomainSpecAsNeeded(domainSpec);
assertTrue("Message logged: " + handler.getAllFormattedMessage(), handler.hasWarningMessageWithSubString("No servers configured in WebLogic cluster with name noSuchCluster"));
} finally {
TestUtil.removeLogHandler(wlsClusterConfig, handler);
}
}
Aggregations