use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.
the class RestBackendImpl method updateReplicasForDomain.
private void updateReplicasForDomain(String namespace, Domain domain, String cluster, int managedServerCount) {
// Capacity of configured cluster is valid for scaling
// Set replicas value on corresponding ClusterStartup (if defined)
// or on the Domain level replicas value for cluster not defined in a ClusterStartup
String domainUID = domain.getSpec().getDomainUID();
boolean domainModified = false;
ClusterStartup clusterStartup = getClusterStartup(domain, cluster);
int currentReplicasCount = clusterStartup != null ? clusterStartup.getReplicas() : domain.getSpec().getReplicas();
if (managedServerCount != currentReplicasCount) {
if (clusterStartup != null) {
// set replica value on corresponding ClusterStartup
clusterStartup.setReplicas(managedServerCount);
domainModified = true;
} else if (StartupControlConstants.AUTO_STARTUPCONTROL.equals(domain.getSpec().getStartupControl())) {
// set replica on Domain for cluster not defined in ClusterStartup
domain.getSpec().setReplicas(managedServerCount);
domainModified = true;
} else {
// so scaling will not occur since Domain.spec.Replicas property will be ignored.
throw createWebApplicationException(Status.BAD_REQUEST, MessageKeys.SCALING_AUTO_CONTROL_AUTO, cluster);
}
}
if (domainModified) {
try {
CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
// Write out the Domain with updated replica values
// TODO: Can we patch instead of replace?
factory.create().replaceDomain(domainUID, namespace, domain);
} catch (ApiException e) {
LOGGER.finer("Unexpected exception when updating Domain " + domainUID + " in namespace " + namespace, e);
throw new WebApplicationException(e.getMessage());
}
}
}
use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method createSecret.
// Create a named secret with username / password in specified name
private V1Secret createSecret(String name, String namespace) throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
try {
V1Secret existing = factory.create().readSecret(name, namespace);
if (existing != null)
return existing;
} catch (ApiException ignore) {
// Just ignore and try to create it
}
if (isVersion18)
return null;
V1Secret body = new V1Secret();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Secret");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(name);
meta.setNamespace(namespace);
body.setMetadata(meta);
Map<String, byte[]> data = new HashMap<String, byte[]>();
data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME, USERNAME.getBytes());
data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD, PASSWORD.getBytes());
body.setData(data);
try {
return factory.create().createSecret(namespace, body);
} catch (Exception e) {
e.printStackTrace(System.out);
throw e;
}
}
use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method createNamespace.
// Create a named namespace
private V1Namespace createNamespace(String name) throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
try {
V1Namespace existing = factory.create().readNamespace(name);
if (existing != null)
return existing;
} catch (ApiException ignore) {
// Just ignore and try to create it
}
V1Namespace body = new V1Namespace();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Namespace");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(name);
body.setMetadata(meta);
return factory.create().createNamespace(body);
}
use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method setUp.
@Before
public void setUp() throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
// Determine if 1.8 since some bugs with kubernetes-client / java and secrets
VersionInfo verInfo = factory.create().readVersionCode();
if ("1".equals(verInfo.getMajor()) && "8".equals(verInfo.getMinor())) {
isVersion18 = true;
}
createNamespace(UNIT_NAMESPACE);
createSecret(SECRET_NAME, UNIT_NAMESPACE);
createInvalidSecret(INVALID_SECRET_NAME, UNIT_NAMESPACE);
createSecret(SECRET_NAME, "default");
defaultSecretHelper = new SecretHelper("default");
unitSecretHelper = new SecretHelper(UNIT_NAMESPACE);
}
use of oracle.kubernetes.operator.helpers.CallBuilderFactory in project weblogic-kubernetes-operator by oracle.
the class ServiceHelperTest method tearDown.
@After
public void tearDown() throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
// Delete the service if we created one.
if (serviceCreated) {
System.out.println("Deleting service post-test");
factory.create().deleteService("domain-uid-admin", "tests");
serviceCreated = false;
}
}
Aggregations