#/*******************************************************************************
# * Copyright (c) 2013 GigaSpaces Technologies Ltd. All rights reserved
# *
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *       http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
#    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    * See the License for the specific language governing permissions and
#    * limitations under the License.
# *******************************************************************************/

"""
Celery tasks for running recipes through chef-client.

This file implements the AppModule.installer interface, where for each of tasks, we check that chef is configured
and run the relevant runlist using the chef_client module.
"""

from celery.utils.log import get_task_logger
from cosmo.celery import celery
from chef_client_common.chef_client import set_up_chef_client, run_chef

logger = get_task_logger(__name__)


@celery.task
@set_up_chef_client
def deploy(chef_deploy_runlist, chef_attributes, **kwargs):
    run_chef(chef_deploy_runlist, chef_attributes)


@celery.task
@set_up_chef_client
def undeploy(chef_undeploy_runlist, chef_attributes, **kwargs):
    run_chef(chef_undeploy_runlist, chef_attributes)


@celery.task
@set_up_chef_client
def start(chef_start_runlist, chef_attributes, **kwargs):
    run_chef(chef_start_runlist, chef_attributes)


@celery.task
@set_up_chef_client
def stop(chef_stop_runlist, chef_attributes, **kwargs):
    run_chef(chef_stop_runlist, chef_attributes)

@@ -1049,16 +1049,74 @@
 e.%0A%22%22%22%0A%0A
+from cosmo.events import send_event, get_cosmo_properties%0A
 from cel
@@ -1635,16 +1635,31 @@
 f start(
+__cloudify_id, 
 chef_sta
@@ -1678,32 +1678,48 @@
 chef_attributes,
+ policy_service,
  **kwargs):%0A    
@@ -1756,32 +1756,144 @@
 hef_attributes)%0A
+    host = get_cosmo_properties()%5B'ip'%5D%0A    send_event(__cloudify_id, host, policy_service, %22state%22, %22running%22)%0A
 %0A%0A@celery.task%0A@

send riemann started event after executing start runlist