Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of https://github.com/tengu-team/layer-sojobo
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
sebastienpattyn93 committed Apr 20, 2018
2 parents 8466b0b + 49d0288 commit 6e55721
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
9 changes: 9 additions & 0 deletions files/sojobo_api/api/w_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,12 @@ def get_all_bundle_types():
def clear_bundle_types():
aql = "FOR b IN bundleTypes REMOVE b IN bundleTypes"
execute_aql_query(aql, rawResults=True)

###############################################################################
# MONITORING #
###############################################################################


def set_monitoring_state(m_key, state):
aql = "UPDATE {_key: @m_key, monitoring_state: @state} IN models"
execute_aql_query(aql, m_key=m_key, state=state)
34 changes: 31 additions & 3 deletions files/sojobo_api/api/w_juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,15 @@ def create_model(authorization, m_name, cred_name, c_name, workspace_type=None):
# Create the model in ArangoDB. Add model key to controller and
# set the model access level of the user.
new_model = datastore.create_model(m_key, m_name, state='deploying')
# TODO: Maybe put these 3 datastore methods in one so you do not have
# to create a connection with ArangoDB each time.
datastore.add_model_to_controller(c_name, m_key)
datastore.set_model_state(m_key, 'accepted')
datastore.set_model_access(m_key, authorization.username, 'admin')
if workspace_type:
datastore.add_edge_between_model_and_workspace_type(new_model["_key"], workspace_type)
# Run the background script, this creates the model in JuJu.
Popen(["python3", "{}/scripts/add_model.py".format(settings.SOJOBO_API_DIR),
c_name, m_key, m_name, authorization.username, authorization.password, cred_name, str(workspace_type)])
c_name, m_key, m_name, authorization.username,
authorization.password, cred_name, str(workspace_type)])
return 202, "Model is being deployed."
else:
return errors.already_exists('model')
Expand Down Expand Up @@ -1090,3 +1089,32 @@ def log_event(event_type, tags):
current_time = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
from sojobo_api.api import w_events as events
events.log_event(event_type, current_time, tags)

###############################################################################
# MONITORING #
###############################################################################


def add_monitoring_to_app(c_name, endpoint, cacert, m_name, uuid, juju_username, password, application):
if os.path.isfile("{}/monitoring_settings.py".format(settings.SOJOBO_API_DIR)):
from sojobo_api.api import w_monitoring_logic
w_monitoring_logic.add_monitoring_to_app(c_name, endpoint, cacert,
m_name, uuid, juju_username,
password, application)


def monitoring_enabled(model_info):
if os.path.isfile("{}/monitoring_settings.py".format(settings.SOJOBO_API_DIR)):
from sojobo_api.api import w_monitoring_logic
return w_monitoring_logic.monitoring_enabled(model_info)
else:
return False


def update_monitoring_relations(c_name, endpoint, cacert, m_name, uuid,
juju_username, password, applications_info):
if os.path.isfile("{}/monitoring_settings.py".format(settings.SOJOBO_API_DIR)):
from sojobo_api.api import w_monitoring_logic
w_monitoring_logic.update_monitoring_relations(c_name, endpoint, cacert,
m_name, uuid, juju_username,
password, applications_info)
17 changes: 17 additions & 0 deletions files/sojobo_api/scripts/add_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ async def add_application(c_name, m_key, username, password, units, machine, con
)

await app_facade.Deploy([app])

# If monitoring is enabled for the workspace then we need to add a
# relation between the application and the tengu monitoring telegraf.
if juju.monitoring_enabled(auth_data["model"]):
m_name = auth_data["model"]["name"]
logger.info('Updating monitoring relations for %s:%s', c_name, m_name)
applications_info = juju.get_applications_info(model_connection)
endpoint = auth_data["controller"]["endpoints"][0]
cacert = auth_data["controller"]["ca_cert"]
uuid = auth_data["model"]["uuid"]
juju_username = auth_data["user"]["juju_username"]
juju.update_monitoring_relations(c_name, endpoint, cacert, m_name,
uuid, juju_username, password,
applications_info)
juju.add_monitoring_to_app(c_name, endpoint, cacert, m_name,
uuid, juju_username, password, application)

await model_connection.disconnect()
logger.info('Application %s succesfully added!', application)
except Exception as e:
Expand Down
14 changes: 14 additions & 0 deletions files/sojobo_api/scripts/bundle_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ async def deploy_bundle(username, password, c_name, m_name, bundle):
for app_name in pending_apps
], loop=model.loop)
logger.info('Bundle successfully deployed for %s:%s', c_name, m_name)


if juju.monitoring_enabled(auth_data["model"]):
logger.info('Updating monitoring relations for %s:%s', c_name, m_name)
applications_info = juju.get_applications_info(model)
endpoint = auth_data["controller"]["endpoints"][0]
cacert = auth_data["controller"]["ca_cert"]
uuid = auth_data["model"]["uuid"]
juju_username = auth_data["user"]["juju_username"]
juju.update_monitoring_relations(c_name, endpoint, cacert, m_name,
uuid, juju_username, password,
applications_info)


await model.disconnect()
logger.info('Successfully disconnected %s', m_name)
shutil.rmtree(dirpath)
Expand Down

0 comments on commit 6e55721

Please sign in to comment.