Add counters for generated notifications.
[sim/o1-interface.git] / ntsimulator / src / ntsimulator-manager / simulator-operations.c
index 29f8147..5f55f4e 100644 (file)
@@ -1,9 +1,19 @@
-/*
- * simulator-operations.c
- *
- *  Created on: Mar 9, 2019
- *      Author: parallels
- */
+/*************************************************************************
+*
+* Copyright 2019 highstreet technologies GmbH and others
+*
+* 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.
+***************************************************************************/
 
 #include "simulator-operations.h"
 #include "sysrepo.h"
@@ -82,8 +92,8 @@ static cJSON* get_docker_container_bindings(void)
        curl_easy_reset(curl);
        set_curl_common_info();
 
-       char url[100];
-       sprintf(url, "http:/v%s/containers/NTS_Manager/json", getenv("DOCKER_ENGINE_VERSION"));
+       char url[200];
+       sprintf(url, "http:/v%s/containers/%s/json", getenv("DOCKER_ENGINE_VERSION"), getenv("HOSTNAME"));
 
        curl_easy_setopt(curl, CURLOPT_URL, url);
 
@@ -243,6 +253,12 @@ static char* create_docker_container_curl(int base_netconf_port, cJSON* managerB
        return NULL;
     }
 
+       if (cJSON_AddStringToObject(labels, "NTS_Manager", getenv("HOSTNAME")) == NULL)
+    {
+       printf("Could not create JSON object: NTS Manager\n");
+       return NULL;
+    }
+
     cJSON *env_variables_array = cJSON_CreateArray();
     if (env_variables_array == NULL)
        {
@@ -892,6 +908,12 @@ int stop_device(device_stack_t *theStack)
                printf("Could not kill and remove docker container with uuid=\"%s\"\n", last_id);
        }
 
+    rc = removeDeviceEntryFromStatusFile(last_id);
+    if (rc != SR_ERR_OK)
+    {
+        printf("Could not remove entry from status file for uuid=\"%s\"\n", last_id);
+    }
+
        pop_device(theStack);
 
        return SR_ERR_OK;
@@ -1011,6 +1033,7 @@ int get_docker_containers_operational_state_curl(device_stack_t *theStack)
                                        if (rc != SR_ERR_OK)
                                        {
                                                printf("Could not set the operational state for the device with uuid=\"%s\"\n", container_id_short);
+                                               return SR_ERR_OPERATION_FAILED;
                                        }
                                }
                        }
@@ -1082,7 +1105,7 @@ int notification_delay_period_changed(int period)
        if (!cJSON_IsObject(notifConfig))
        {
                printf("Configuration JSON is not as expected: notification-config is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1090,7 +1113,7 @@ int notification_delay_period_changed(int period)
        if (!cJSON_IsNumber(faultNotifDelay))
        {
                printf("Configuration JSON is not as expected: fault-notification-delay-period is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1101,7 +1124,7 @@ int notification_delay_period_changed(int period)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }
@@ -1135,7 +1158,7 @@ int ves_heartbeat_period_changed(int period)
        if (!cJSON_IsObject(notifConfig))
        {
                printf("Configuration JSON is not as expected: notification-config is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1143,7 +1166,7 @@ int ves_heartbeat_period_changed(int period)
        if (!cJSON_IsNumber(vesHeartbeatPeriod))
        {
                printf("Configuration JSON is not as expected: ves-heartbeat-period is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1154,7 +1177,7 @@ int ves_heartbeat_period_changed(int period)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }
@@ -1386,7 +1409,7 @@ int ves_ip_changed(char *new_ip)
        if (!cJSON_IsObject(vesDetails))
        {
                printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1394,7 +1417,7 @@ int ves_ip_changed(char *new_ip)
        if (!cJSON_IsString(vesIp))
        {
                printf("Configuration JSON is not as expected: ves-endpoint-ip is not a string");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1405,7 +1428,7 @@ int ves_ip_changed(char *new_ip)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }
@@ -1439,7 +1462,7 @@ int ves_port_changed(int new_port)
        if (!cJSON_IsObject(vesDetails))
        {
                printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1447,7 +1470,7 @@ int ves_port_changed(int new_port)
        if (!cJSON_IsNumber(vesPort))
        {
                printf("Configuration JSON is not as expected: ves-endpoint-port is not a number.");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1458,7 +1481,7 @@ int ves_port_changed(int new_port)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }
@@ -1492,7 +1515,7 @@ int ves_registration_changed(cJSON_bool new_bool)
        if (!cJSON_IsObject(vesDetails))
        {
                printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1500,7 +1523,7 @@ int ves_registration_changed(cJSON_bool new_bool)
        if (!cJSON_IsBool(vesRegistration))
        {
                printf("Configuration JSON is not as expected: ves-registration is not a bool.");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1511,7 +1534,7 @@ int ves_registration_changed(cJSON_bool new_bool)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }
@@ -1545,7 +1568,7 @@ int is_netconf_available_changed(cJSON_bool new_bool)
        if (!cJSON_IsObject(notifConfig))
        {
                printf("Configuration JSON is not as expected: notification-config is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1553,7 +1576,7 @@ int is_netconf_available_changed(cJSON_bool new_bool)
        if (!cJSON_IsBool(isNetconfAvailable))
        {
                printf("Configuration JSON is not as expected: is-netconf-available is not a bool.");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1564,7 +1587,7 @@ int is_netconf_available_changed(cJSON_bool new_bool)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }
@@ -1598,7 +1621,7 @@ int is_ves_available_changed(cJSON_bool new_bool)
        if (!cJSON_IsObject(notifConfig))
        {
                printf("Configuration JSON is not as expected: notification-config is not an object");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1606,7 +1629,7 @@ int is_ves_available_changed(cJSON_bool new_bool)
        if (!cJSON_IsBool(isVesAvailable))
        {
                printf("Configuration JSON is not as expected: is-ves-available is not a bool.");
-               free(jsonConfig);
+               cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
@@ -1617,7 +1640,7 @@ int is_ves_available_changed(cJSON_bool new_bool)
        stringConfiguration = cJSON_Print(jsonConfig);
        writeConfigFile(stringConfiguration);
 
-       free(jsonConfig);
+       cJSON_Delete(jsonConfig);
 
        return SR_ERR_OK;
 }