Skip to content
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

WIP: Bundled autoscale library into project #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions project.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
name = pbspro
label = PBS Professional OSS
type = scheduler
version = 1.2.0
version = 1.3.0
autoupgrade = true

[blobs]
Files = pbspro-execution-18.1.3-0.x86_64.rpm, pbspro-server-18.1.3-0.x86_64.rpm
Files = pbspro-execution-18.1.3-0.x86_64.rpm, pbspro-server-18.1.3-0.x86_64.rpm, autoscale-7.8.0.tar.gz

[spec master]
run_list = role[pbspro_master_role]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@


default[:pbspro][:autoscale_hook][:__comment__] = "This file was generated by serializing node[:cyclecloud][:pbspro][:autostart_hook]."
default[:pbspro][:autoscale_hook][:src_dirs] = ["#{node[:cyclecloud][:home]}/system/embedded/lib/python2.7/site-packages",
"#{node[:cyclecloud][:bootstrap]}/pbs"
]
default[:pbspro][:autoscale_hook][:src_dirs] = ["#{node[:cyclecloud][:bootstrap]}/pbs"]
# pass through to the hook config json file
default[:pbspro][:autoscale_hook][:pbs_bootstrap] = "#{node[:cyclecloud][:bootstrap]}/pbs"
default[:pbspro][:autoscale_hook][:cyclecloud_home] = node[:cyclecloud][:home]
default[:pbspro][:autoscale_hook][:autostart_log_level] = "DEBUG"
default[:pbspro][:autoscale_hook][:autostart_log_file_level] = "DEBUG"
Expand Down
24 changes: 12 additions & 12 deletions specs/default/chef/site-cookbooks/pbspro/files/default/autostart.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import time
import traceback

from cyclecloud import machine, clustersapi, autoscale_util, autoscaler as autoscalerlib
from cyclecloud.autoscale_util import Record
import cyclecloud.config
from cyclecloud.job import Job, PackingStrategy
from autoscale import machine, clustersapi, autoscale_util, autoscaler as autoscalerlib
from autoscale.autoscale_util import Record
import autoscale.config
from autoscale.job import Job, PackingStrategy
import mockpbs
import pbs_driver
from pbscc import InvalidSizeExpressionError
Expand All @@ -24,10 +24,10 @@

class PBSAutostart:
'''
1) Converts existing pbsnodes into cyclecloud.machine.Machine instances
1) Converts existing pbsnodes into autoscale.machine.Machine instances
2) Performs a 'true up' of the machine instances reported by the autoscale lib vs the machines discovered in step 1) using InstanceId.
3) Converts PBS jobs into cyclecloud.job.Job instances.
4) Uses the current state of the cluster (steps 1 and 2) to construct a cyclecloud.autoscaler.Autoscaler instance.
3) Converts PBS jobs into autoscale.job.Job instances.
4) Uses the current state of the cluster (steps 1 and 2) to construct a autoscale.autoscaler.Autoscaler instance.
5) Feeds in jobs from step 3) into the Autoscaler, which performs a demand calculation of exactly which new machines are needed and which are idle.
6) Does a soft shutdown of idle nodes - first it sets them offline - `pbsnodes -o` - then, on subsequent iterations, if no jobs running on the node it
performs a shutdown.
Expand All @@ -43,7 +43,7 @@ def __init__(self, driver, clusters_api, cc_config):

def query_jobs(self):
'''
Converts PBS jobs into cyclecloud.job.Job instances. It will also compress jobs that have the exact same requirements.
Converts PBS jobs into autoscale.job.Job instances. It will also compress jobs that have the exact same requirements.
'''
scheduler_config = self.driver.scheduler_config()
scheduler_resources = [] + scheduler_config["resources"]
Expand Down Expand Up @@ -232,7 +232,7 @@ def fetch_nodearray_definitions(self):
A wrapper around the autoscale library function to parse Configuration.autoscale.* chef attributes and add
the 'ungrouped' attribute to the machine types.

See cyclecloud.nodearrays.NodearrayDefinitions for more info.
See autoscale.nodearrays.NodearrayDefinitions for more info.
'''
nodearray_definitions = machine.fetch_nodearray_definitions(self.clusters_api, self.default_placement_attrs)
nodearray_definitions.placement_group_optional = True
Expand Down Expand Up @@ -378,7 +378,7 @@ def autoscale(self):

def get_existing_machines(self, nodearray_definitions):
'''
Queries pbsnodes and CycleCloud to get a sane set of cyclecloud.machine.Machine instances that represent the current state of the cluster.
Queries pbsnodes and CycleCloud to get a sane set of autoscale.machine.Machine instances that represent the current state of the cluster.
'''
pbsnodes = self.driver.pbsnodes().get(None)
existing_machines = []
Expand Down Expand Up @@ -421,7 +421,7 @@ def process_pbsnode(self, pbsnode, instance_ids_to_shutdown, nodearray_definitio
If the pbsnode is offline, will handle evaluating whether the node can be shutdown. See instance_ids_to_shutdown, which
is an OUT parameter here.

Otherwise convert the pbsnode into a cyclecloud.machine.Machine instance.
Otherwise convert the pbsnode into a autoscale.machine.Machine instance.
'''
states = set(pbsnode["state"].split(","))
resources = pbsnode["resources_available"]
Expand Down Expand Up @@ -537,7 +537,7 @@ def _hook():
else:
pbscc.debug("No overrides exist in file %s" % pbscc.CONFIG_PATH)

cc_config = cyclecloud.config.new_provider_config(overrides=overrides)
cc_config = autoscale.config.new_provider_config(overrides=overrides)

if len(sys.argv) < 3:
# There are no env variables for this as far as I can tell.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ def perform_hook():
"AUTOSTART_LOG_FILE_LEVEL": hook_config.get("autostart_log_file_level") or "DEBUG",
"AUTOSTART_LOG_LEVEL": hook_config.get("autostart_log_level") or "DEBUG"}

jetpack_config = hook_config.get("jetpack_python")
if not jetpack_config:
if not hook_config.get("cyclecloud_home"):
raise RuntimeError("Please specify either jetpack_python or cyclecloud_home in the hook config.")

hook_config["jetpack_python"] = os.path.join(hook_config["cyclecloud_home"], "system", "embedded", "bin", "python")
jetpack_python = hook_config.get("pbs_bootstrap") + "/venv/bin/python"

pbs_bin_dir = os.path.join(pbs.pbs_conf["PBS_EXEC"], "bin")

cmd = [hook_config["jetpack_python"], "-m", "autostart", pbs.hook_config_filename, pbs_bin_dir]
cmd = [jetpack_python, "-m", "autostart", pbs.hook_config_filename, pbs_bin_dir]

pbs.logmsg(pbs.LOG_DEBUG, "Running %s with environment %s" % (cmd, env_with_src_dirs))

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env_with_src_dirs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import unittest

from autostart import PBSAutostart
from cyclecloud import machine, autoscale_util
from cyclecloud.job import Job
from cyclecloud.machine import MachineRequest
from cyclecloud.autoscale_util import Record
from autoscale import machine, autoscale_util
from autoscale.job import Job
from autoscale.machine import MachineRequest
from autoscale.autoscale_util import Record
import time
from itertools import chain
from cyclecloud.config import InstanceConfig
from autoscale.config import InstanceConfig
import random
import pbscc
from pbscc import InvalidSizeExpressionError
Expand Down
12 changes: 12 additions & 0 deletions specs/default/chef/site-cookbooks/pbspro/recipes/autostart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
content Chef::JSONCompat.to_json_pretty(node[:pbspro][:autoscale_hook])
end

sdist_name = "autoscale-7.8.0.tar.gz"

jetpack_download sdist_name do
project 'pbspro'
end

bash "create pbs virtualenv" do
code "virtualenv --system-site-packages '#{node[:cyclecloud][:bootstrap]}/pbs/venv'
source '#{node[:cyclecloud][:bootstrap]}/pbs/venv/bin/activate'
pip install '#{node[:jetpack][:downloads]}/#{sdist_name}'"
end

bash "import autoscale hook" do
code <<-EOH
set -e
Expand Down
10 changes: 6 additions & 4 deletions specs/master/cluster-init/tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Licensed under the MIT License.
#
import unittest
from tryme import retry, Stop, Again
import os
import helper
import time
import logging
import helper
import jetpack
from tryme import retry, Stop, Again

jetpack.util.setup_logging()

Expand Down Expand Up @@ -79,8 +80,9 @@ def setUp(self):

def test_simple(self):
sleep_script = write_sleep_script()
output_file = self.userhome + '/sleep.out'
err_file = self.userhome + '/sleep.err'
jobtime = str(int(time.time()))
output_file = '%s/sleep.%s.out' % (self.userhome, jobtime)
err_file = '%s/sleep.%s.err' % (self.userhome, jobtime)
helper.sudo_check_output(['/opt/pbs/bin/qsub', '-o',
output_file, '-e', err_file, sleep_script],
CLUSTER_USER, cwd=self.userhome)
Expand Down