Skip to content

Commit

Permalink
Added support for Integration Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
AnykeyNL committed Aug 21, 2020
1 parent e83f67c commit f03f2ac
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 33 deletions.
112 changes: 83 additions & 29 deletions AutoScaleALL.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, threadID, ID, NAME, CPU):
self.NAME = NAME
self.CPU = CPU
def run(self):
MakeLog("Starting Autonomous DB {} and after that scaling to {} cpus".format(self.NAME, self.CPU) )
MakeLog(" - Starting Autonomous DB {} and after that scaling to {} cpus".format(self.NAME, self.CPU) )
Retry = True
while Retry:
try:
Expand All @@ -79,7 +79,7 @@ def run(self):
time.sleep(RateLimitDelay)
else:
ErrorsFound = True
errors.append("Error ({}) Starting Autonomous DB {}".format(response.status, self.NAME))
errors.append(" - Error ({}) Starting Autonomous DB {}".format(response.status, self.NAME))
Retry = False

while response.data.lifecycle_state != "AVAILABLE":
Expand All @@ -99,7 +99,7 @@ def run(self):
MakeLog("Rate limit kicking in.. waiting {} seconds...".format(RateLimitDelay))
time.sleep(RateLimitDelay)
else:
errors.append("Error ({}) re-scaling to {} cpus for {}".format(response.status, self.CPU, self.NAME))
errors.append(" - Error ({}) re-scaling to {} cpus for {}".format(response.status, self.CPU, self.NAME))
Retry = False

class PoolThread (threading.Thread):
Expand All @@ -110,19 +110,19 @@ def __init__(self, threadID, ID, NAME, INSTANCES):
self.NAME = NAME
self.INSTANCES = INSTANCES
def run(self):
MakeLog("Starting Instance Pool {} and after that scaling to {} instances".format(self.NAME, self.INSTANCES) )
MakeLog(" - Starting Instance Pool {} and after that scaling to {} instances".format(self.NAME, self.INSTANCES) )
Retry = True
while Retry:
try:
response = pool.start_instance_pool(instance_pool_id=self.ID)
Retry = False
success.append("Starting Instance Pool {}".format(self.NAME))
success.append(" - Starting Instance Pool {}".format(self.NAME))
except oci.exceptions.ServiceError as response:
if response.status == 429:
MakeLog("Rate limit kicking in.. waiting {} seconds...".format(RateLimitDelay))
time.sleep(RateLimitDelay)
else:
errors.append("Error ({}) starting instance pool {}".format(response.status, self.NAME))
errors.append(" - Error ({}) starting instance pool {}".format(response.status, self.NAME))
Retry = False

while response.data.lifecycle_state != "RUNNING":
Expand All @@ -143,7 +143,7 @@ def run(self):
time.sleep(RateLimitDelay)
else:
ErrorsFound = True
errors.append("Error ({}) rescaling instance pool {}".format(response.status, self.NAME))
errors.append(" - Error ({}) rescaling instance pool {}".format(response.status, self.NAME))
Retry = False

if UseInstancePrinciple:
Expand Down Expand Up @@ -171,6 +171,7 @@ def run(self):
ns = oci.ons.NotificationDataPlaneClient(config={}, signer=signer)
oda= oci.oda.OdaClient(config={}, signer=signer)
analytics = oci.analytics.AnalyticsClient(config={}, signer=signer)
integration = oci.integration.IntegrationInstanceClient(config={}, signer=signer)

while SearchRootID:
compartment = identity.get_compartment(compartment_id=SearchCompID).data
Expand All @@ -191,6 +192,7 @@ def run(self):
ns = oci.ons.NotificationDataPlaneClient(config)
oda = oci.oda.OdaClient(config)
analytics = oci.analytics.AnalyticsClient(config)
integration = oci.integration.IntegrationInstanceClient(config)
user = identity.get_user(config["user"]).data
userName = user.description
RootCompartmentID = config["tenancy"]
Expand Down Expand Up @@ -268,7 +270,10 @@ def run(self):

# if schedule validated, let see if we can apply the new schedule to the resource
if ActiveSchedule != "":
MakeLog(" - Active schedule for {} : {}".format(resource.display_name, ActiveSchedule))
p1 = CurrentHour*2
p2 = CurrentHour*2+1
DisplaySchedule = ActiveSchedule[:p1] + "[" + ActiveSchedule[p1:p2] + "]" + ActiveSchedule[p2:]
MakeLog(" - Active schedule for {} : {}".format(resource.display_name, DisplaySchedule))

# Execute On/Off operations for compute VMs
if resource.resource_type == "Instance":
Expand Down Expand Up @@ -710,28 +715,37 @@ def run(self):
goscale = True

if goscale:
MakeLog(" - Initiate Analytics Scaling from {} to {}oCPU for {}".format(
int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
Retry = True
while Retry:
try:
response = analytics.scale_analytics_instance(analytics_instance_id=resource.identifier,scale_analytics_instance_details=details)
Retry = False
success.append(" - Initiate Analytics Scaling from {} to {}oCPU for {}".format(int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]), resource.display_name))
except oci.exceptions.ServiceError as response:
if response.status == 429:
MakeLog("Rate limit kicking in.. waiting {} seconds...".format(RateLimitDelay))
time.sleep(RateLimitDelay)
else:
ErrorsFound = True
errors.append(
" - Error ({}) Analytics scaling from {} to {}oCPU for {}".format(response.status, int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
MakeLog(
" - Error ({}) Analytics scaling from {} to {}oCPU for {}".format(response.status, int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
goscale = False
if Action == "All":
goscale = True
elif int(resourceDetails.capacity.capacity_value) < int(schedulehours[CurrentHour]) and Action == "Up":
goscale = True
elif int(resourceDetails.capacity.capacity_value) > int(schedulehours[CurrentHour]) and Action == "Down":
goscale = True

if goscale:
MakeLog(" - Initiate Analytics Scaling from {} to {}oCPU for {}".format(
int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
Retry = True
while Retry:
try:
response = analytics.scale_analytics_instance(analytics_instance_id=resource.identifier,scale_analytics_instance_details=details)
Retry = False
success.append(" - Initiate Analytics Scaling from {} to {}oCPU for {}".format(int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]), resource.display_name))
except oci.exceptions.ServiceError as response:
if response.status == 429:
MakeLog("Rate limit kicking in.. waiting {} seconds...".format(RateLimitDelay))
time.sleep(RateLimitDelay)
else:
ErrorsFound = True
errors.append(
" - Error ({}) Analytics scaling from {} to {}oCPU for {}".format(response.status, int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
MakeLog(
" - Error ({}) Analytics scaling from {} to {}oCPU for {}".format(response.status, int(resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
Retry = False
else:
errors.append(
" - Error (Analytics scaling from {} to {}oCPU, invalid combination for {}".format(int(
Expand All @@ -741,6 +755,46 @@ def run(self):
" - Error (Analytics scaling from {} to {}oCPU, invalid combination for {}".format(int(
resourceDetails.capacity.capacity_value), int(schedulehours[CurrentHour]),
resource.display_name))
if resource.resource_type == "IntegrationInstance":
if int(schedulehours[CurrentHour]) == 0 or int(schedulehours[CurrentHour]) == 1:
resourceDetails = integration.get_integration_instance(integration_instance_id=resource.identifier).data

if resourceDetails.lifecycle_state == "ACTIVE" and int(schedulehours[CurrentHour]) == 0:
if Action == "All" or Action == "Down":
MakeLog(" - Initiate Integration Service shutdown for {}".format(resource.display_name))
Retry = True
while Retry:
try:
response = integration.stop_integration_instance(integration_instance_id=resource.identifier)
Retry = False
success.append(" - Initiate Integration Service shutdown for {}".format(resource.display_name))
except oci.exceptions.ServiceError as response:
if response.status == 429:
MakeLog("Rate limit kicking in.. waiting {} seconds...".format(RateLimitDelay))
time.sleep(RateLimitDelay)
else:
ErrorsFound = True
errors.append(" - Error ({}) Integration Service Shutdown for {}".format(response.status, resource.display_name))
MakeLog(" - Error ({}) Integration Service Shutdown for {}".format(response.status, resource.display_name))
Retry = False

if resourceDetails.lifecycle_state == "INACTIVE" and int(schedulehours[CurrentHour]) == 1:
if Action == "All" or Action == "Up":
MakeLog(" - Initiate Integration Service startup for {}".format(resource.display_name))
Retry = True
while Retry:
try:
response = integration.start_integration_instance(integration_instance_id=resource.identifier)
Retry = False
success.append(" - Initiate Integration Service startup for {}".format(resource.display_name))
except oci.exceptions.ServiceError as response:
if response.status == 429:
MakeLog("Rate limit kicking in.. waiting {} seconds...".format(RateLimitDelay))
time.sleep(RateLimitDelay)
else:
ErrorsFound = True
errors.append(" - Error ({}) Integration Service startup for {}".format(response.status, resource.display_name))
Retry = False


# Wait for any AutonomousDB and Instance Pool Start and rescale tasks completed
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ Welcome to the Scheduled Auto Scaling Script for OCI (Oracle Cloud Infrastructur
The **AutoScaleALL** script: A single Auto Scaling script for all OCI resources that support scaling up/down and power on/off operations.

# NEW
- Added support for Digital Assistant and Analytics Cloud
- Added support for Integration Service,Digital Assistant and Analytics Cloud
- Each service with a Schedule is displayed, the value between [ ] show the current hour schedule

# Supported services
- Compute VMs: On/Off
- Instance Pools: On/Off and Scaling (# of instances)
- Database VMs: On/Off
- Database Baremetal Servers: Scaling (# of CPUs)
- Autonomous Database: On/Off and Scaling (# of CPUs)
- Autonomous Databases: On/Off and Scaling (# of CPUs)
- Oracle Digital Assistant: On/Off
- Oracle Analytics Cloud: On/Off and Scaling (between 2 and8 and 10-12)
- Oracle Analytics Cloud: On/Off and Scaling (between 2-8 oCPU and 10-12 oCPU)
- Oracle Integration Service: On/Off

# Features
- Support for using the script with Instance Principle. Meaning you can run this script inside OCI and when configured properly, you do not need to provide any details or credentials.
Expand All @@ -26,7 +28,7 @@ localize this, that is possible in the script. For the predefined tag, you need

A single resource can contain multiple tags. A Weekend/Weekday tag overrules an AnyDay tag. A specific day of the week tag (ie. Monday) overrules all other tags.

The value of the tag needs to contain 24 numbers (else it is ignored), seperated by commas. If the value is 0 it will power off the resource (if that is supported for that resource). Any number higher then 0 will re-scale the resource to that number. If the resource is powered off, it first will power-on the resource and then scale to the correct size.
The value of the tag needs to contain 24 numbers (else it is ignored), separated by commas. If the value is 0 it will power off the resource (if that is supported for that resource). Any number higher then 0 will re-scale the resource to that number. If the resource is powered off, it first will power-on the resource and then scale to the correct size.

![Scaling Example Instance Pool](http://oc-blog.com/wp-content/uploads/2019/06/ScaleExamplePool.png)

Expand Down

0 comments on commit f03f2ac

Please sign in to comment.