Skip to content

Owls83995 - Sample scripts to shutdown and start a specific managed server/cluster/domain #2002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4d6de23
owls-83995 - Scripts to start/stop a managed server/cluster/domain
ankedia Oct 20, 2020
e20b630
fix method comments
ankedia Oct 20, 2020
7a2b1e3
Minor changes
ankedia Oct 20, 2020
cf096af
Address review comments and fix script comments/usages.
ankedia Oct 21, 2020
302a597
Added integration tests, made few doc changes based on review comment…
ankedia Oct 22, 2020
a134689
Clarify script usage, updated README file and minor changes.
ankedia Oct 22, 2020
97b7fcd
Changes to add script usage details
ankedia Oct 22, 2020
fde5cb8
Address PR review comments
ankedia Oct 22, 2020
2927762
Review comment and cleanup.
ankedia Oct 22, 2020
01e6307
Documentation changes based on PR review comments.
ankedia Oct 23, 2020
4eba072
Fully qualified replica value as per review comments
ankedia Oct 23, 2020
eadad48
edit docs
rosemarymarano Oct 23, 2020
5845883
edit README
rosemarymarano Oct 23, 2020
1fda64a
Address PR review comments
ankedia Oct 23, 2020
71922eb
Changes to address PR review comments and removed ItLifecycleSampleSc…
ankedia Oct 23, 2020
d66c1a8
fix indentation
ankedia Oct 23, 2020
05c5a3f
fix comment and typo
ankedia Oct 23, 2020
0ba9537
Added validation as per review comment.
ankedia Oct 24, 2020
0ab8bd0
changes to address review comment and minor cleanup
ankedia Oct 25, 2020
3950815
PR review comment - changes to assume default policy is IF_NEEDED if …
ankedia Oct 26, 2020
2859f08
changes for new algorithm as documented on http://aseng-wiki.us.oracl…
ankedia Oct 30, 2020
81e0486
More changes for new algorithm.
ankedia Oct 31, 2020
c6c287b
code refactoring and minor doc update.
ankedia Nov 1, 2020
3456c68
Minor change for dynamic server name validation
ankedia Nov 2, 2020
df3c33f
Changes to address review comments.
ankedia Nov 2, 2020
3e028fb
More review comment changes and cleanup.
ankedia Nov 3, 2020
10feb99
Unset policy to start independent (stadalone) maanged server instead …
ankedia Nov 3, 2020
15c725a
Latest review comment changes.
ankedia Nov 3, 2020
e5b1044
More changes based on review comments.
ankedia Nov 4, 2020
b17410a
Chnages for latest review comments.
ankedia Nov 4, 2020
38d442d
Remove unused action variable and assignments.
ankedia Nov 4, 2020
e4bf493
Fix the logic to display error when config map not found and return p…
ankedia Nov 4, 2020
b775210
Changes for latest review comments.
ankedia Nov 4, 2020
c1f109d
Changes for latest round of review comments.
ankedia Nov 4, 2020
2c5ae36
use printError instead of echo
ankedia Nov 4, 2020
899073a
Changes to remove integration tests and doc review comments.
ankedia Nov 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs-source/content/samples/simple/domains/lifecycle/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "Domain lifecycle operations"
date: 2019-02-23T17:32:31-05:00
weight: 8
description: "Start and stop Managed Servers, clusters, and domains."
---

#### Domain lifecycle sample scripts

Beginning in version 3.1.0, the operator provides sample scripts to start up or shut down a specific Managed Server or cluster in a deployed domain, or the entire deployed domain.

**Note**: Prior to running these scripts, you must have previously created and deployed the domain.

The scripts are located in the `kubernetes/samples/scripts/domain-lifecycle` directory. They are helpful when scripting the life cycle of a WebLogic Server domain. For more information, see the [README](https://github.com/oracle/weblogic-kubernetes-operator/tree/master/kubernetes/samples/scripts/domain-lifecycle/README.md).
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ started, or restarted. To start, stop, or restart servers, modify these fields o

* [Starting and stopping servers](#starting-and-stopping-servers)
* [Common starting and stopping scenarios](#common-starting-and-stopping-scenarios)
* [Domain lifecycle sample scripts](#domain-lifecycle-sample-scripts)
* [Shutdown options](#shutdown-options)
* [Restarting servers](#restarting-servers)
* [Rolling restarts](#rolling-restarts)
Expand Down Expand Up @@ -82,6 +83,13 @@ updates before advancing the server to the running state.

Changes to the `serverStartState` property do not affect already started servers.

### Domain lifecycle sample scripts
Beginning in version 3.1.0, the operator provides sample scripts to start up or shut down a specific Managed Server or cluster in a deployed domain, or the entire deployed domain.

**Note**: Prior to running these scripts, you must have previously created and deployed the domain.

The scripts are located in the `kubernetes/samples/scripts/domain-lifecycle` directory. They are helpful when scripting the life cycle of a WebLogic Server domain. For more information, see the [README](https://github.com/oracle/weblogic-kubernetes-operator/tree/master/kubernetes/samples/scripts/domain-lifecycle/README.md).

### Common starting and stopping scenarios

#### Normal running state
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.google.gson.JsonObject;
import io.kubernetes.client.custom.Quantity;
Expand Down Expand Up @@ -50,6 +51,7 @@
import io.kubernetes.client.openapi.models.V1ServiceAccountList;
import io.kubernetes.client.openapi.models.V1Volume;
import io.kubernetes.client.openapi.models.V1VolumeMount;
import oracle.weblogic.domain.Cluster;
import oracle.weblogic.domain.Domain;
import oracle.weblogic.kubernetes.TestConstants;
import oracle.weblogic.kubernetes.actions.TestActions;
Expand Down Expand Up @@ -1629,6 +1631,21 @@ public static void checkServiceDoesNotExist(String serviceName, String namespace
serviceName, namespace)));
}

/**
* Check whether cluster replica count matches with input parameter value.
* @param clusterName Name of cluster to check
* @param domainName Name of domain to which cluster belongs
* @param namespace cluster's namespace
* @param replicaCount replica count value to match
* @return
*/
public static boolean checkClusterReplicaCountMatches(String clusterName, String domainName,
String namespace, Integer replicaCount) throws ApiException {
Cluster cluster = TestActions.getDomainCustomResource(domainName, namespace).getSpec().getClusters()
.stream().filter(c -> c.clusterName().equals(clusterName)).findAny().orElse(null);
return Optional.ofNullable(cluster).get().replicas() == replicaCount;
}

/**
* Create a Docker image for a model in image domain.
*
Expand Down
76 changes: 76 additions & 0 deletions kubernetes/samples/scripts/domain-lifecycle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### Domain lifecycle sample scripts

The operator provides sample scripts to start up or shut down a specific Managed Server or cluster in a deployed domain, or the entire deployed domain.

**Note**: Prior to running these scripts, you must have previously created and deployed the domain.

These scripts can be helpful when scripting the life cycle of a WebLogic Server domain. For information on how to start, stop, restart, and scale WebLogic Server instances in your domain, see [Domain Life Cycle](https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-domains/domain-lifecycle).

#### Scripts to start and stop a Managed Server
The `startServer.sh` script starts a Managed Server either by increasing the `spec.clusters[<cluster-name>].replicas` value for the Managed Server's cluster by `1` or by updating the `spec.managedServers[<server-name>].serverStartPolicy` attribute of the domain resource or both as necessary. The script provides an option to keep the `spec.clusters[<cluster-name>].replicas` value constant for clustered servers. See the script `usage` information by using the `-h` option.

Use the following command to start the server along with increased replica count:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start the server along with increased replica count -> start the server along with an increased replica count OR start the server with an increased replica count

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have reworded it to say "start the server either by increasing the replica count or by updating the server start policy".

```
$ startServer.sh -d domain1 -n weblogic-domain-1 -s managed-server1
[INFO] Updating replica count for cluster 'cluster-1' to 1.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully updated replica count for cluster 'cluster-1' to 1.
```

Use the following command to start the server without increasing replica count:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without increasing replica count -> without increasing the replica count

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

```
$ startServer.sh -d domain1 -n weblogic-domain-1 -s managed-server2 -k
[INFO] Patching start policy for 'managed-server2' to 'ALWAYS'.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully patched server 'managed-server2' with 'ALWAYS' start policy.
```

The `stopServer.sh` script shuts down a running Managed Server either by decreasing the `spec.clusters[<cluster-name>].replicas` value for the Managed Server's cluster by `1` or by patching the `spec.managedServers[<server-name>].serverStartPolicy` attribute of the domain resource or both as necessary. The script provides an option to keep the `spec.clusters[<cluster-name>].replicas` value constant for clustered servers. See the script `usage` information by using the `-h` option.

Use the following command to stop the server along with decreased replica count:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop the server along with decreased replica count -> this does not make sense to me; do you mean stop the server along with decreasing the replica count OR stop the server with a decreased replica count? Please clarify.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to say "stop the server either by decreasing the replica count or by updating the server start policy"

```
$ stopServer.sh -d domain1 -n weblogic-domain-1 -s managed-server1
[INFO] Updating replica count for cluster cluster-1 to 0.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully updated replica count for cluster 'cluster-1' to 0.
```

Use the following command to stop the server without decreasing replica count:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop the server without decreasing replica count -> stop the server without decreasing the replica count

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

```
$ stopServer.sh -d domain1 -n weblogic-domain-1 -s managed-server2 -k
[INFO] Unsetting the current start policy 'ALWAYS' for 'managed-server2'.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully unset policy 'ALWAYS'.
```

### Scripts to start and stop a cluster

The `startCluster.sh` script starts a cluster by patching the `spec.clusters[<cluster-name>].serverStartPolicy` attribute of the domain resource to `IF_NEEDED`. The operator will start the WebLogic Server instance Pods that are part of the cluster after the `serverStartPolicy` attribute is updated to `IF_NEEDED`. See the script `usage` information by using the `-h` option.
```
$ startCluster.sh -d domain1 -n weblogic-domain-1 -c cluster-1
[INFO]Patching start policy of cluster 'cluster-1' from 'NEVER' to 'IF_NEEDED'.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully patched cluster 'cluster-1' with 'IF_NEEDED' start policy!.
```
The `stopCluster.sh` script shuts down a cluster by patching the `spec.clusters[<cluster-name>].serverStartPolicy` attribute of the domain resource to `NEVER`. The operator will shut down the WebLogic Server instance Pods that are part of the cluster after the `serverStartPolicy` attribute is updated to `NEVER`. See the script `usage` information by using the `-h` option.
```
$ stopCluster.sh -d domain1 -n weblogic-domain-1 -c cluster-1
[INFO] Patching start policy of cluster 'cluster-1' from 'IF_NEEDED' to 'NEVER'.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully patched cluster 'cluster-1' with 'NEVER' start policy!
```
### Scripts to start and stop a domain
The `startDomain.sh` script starts a deployed domain by patching the `spec.serverStartPolicy` attribute of the domain resource to `IF_NEEDED`. The operator will start the WebLogic Server instance Pods that are part of the domain after the `spec.serverStartPolicy` attribute of the domain resource is updated to `IF_NEEDED`. See the script `usage` information by using the `-h` option.
```
$ startDomain.sh -d domain1 -n weblogic-domain-1
[INFO] Patching domain 'domain1' from serverStartPolicy='NEVER' to 'IF_NEEDED'.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully patched domain 'domain1' in namespace 'weblogic-domain-1' with 'IF_NEEDED' start policy!
```

The `stopDomain.sh` script shuts down a domain by patching the `spec.serverStartPolicy` attribute of the domain resource to `NEVER`. The operator will shut down the WebLogic Server instance Pods that are part of the domain after the `spec.serverStartPolicy` attribute is updated to `NEVER`. See the script `usage` information by using the `-h` option.
```
$ stopDomain.sh -d domain1 -n weblogic-domain-1
[INFO] Patching domain 'domain1' in namespace 'weblogic-domain-1' from serverStartPolicy='IF_NEEDED' to 'NEVER'.
domain.weblogic.oracle/domain1 patched
[INFO] Successfully patched domain 'domain1' in namespace 'weblogic-domain-1' with 'NEVER' start policy!
Loading