Initial OpenECOMP SDC commit
[sdc.git] / asdc-tests / src / test / resources / CI / importResource / importNormative.sh
1 #!/bin/bash
2
3 function usage {
4         echo "Usage: $0 <hostIp> <hostPort> <userId>"
5 }
6
7 function addResource() {
8         
9         ELEMENT_NAME=$1
10         echo -e "###################### Adding Element ${ELEMENT_NAME} Start ######################"
11         CURRENT_ZIP_FILE=./${ELEMENT_NAME}/normative-types-new-${ELEMENT_NAME}.zip
12         CURRENT_JSON_FILE=./${ELEMENT_NAME}/${ELEMENT_NAME}.json
13         sed -i 's/"userId": ".*",/"userId": "'${ATT_UID}'",/' ${CURRENT_JSON_FILE}
14         JSON_CONTENT=`paste -s ${CURRENT_JSON_FILE}`
15         http_code=$(curl -s -o /dev/null -w "%{http_code}" -v -F resourceMetadata="${JSON_CONTENT}" -F resourceZip=@${CURRENT_ZIP_FILE} -H USER_ID:${ATT_UID} ${HOST_IP}:${HOST_PORT}/sdc2/rest/v1/catalog/upload/multipart)
16         if [ ${http_code} -eq 201  ]; then
17                 echo -e "\n###################### Adding Element ${ELEMENT_NAME} End ########################\n\n\n"
18         elif [ ${http_code} -eq 409 ]; then
19                 echo -e "\n###################### Already exists Element ${ELEMENT_NAME} status code:${http_code} End ########################\n\n\n"
20         elif [ ${http_code} -eq 500 ]; then
21                 echo -e "\n###################### Failed to add Element ${ELEMENT_NAME} status code:${http_code} End ########################\n\n\n"
22                 exit 1
23         fi
24 }
25 if [ $# -lt 3 ]
26 then
27         usage
28         exit 2
29 fi
30
31 HOST_IP=$1
32 HOST_PORT=$2
33 ATT_UID=$3
34
35 #Add The CapabilityTypes
36 http_code=$(curl -s -o /dev/null -w "%{http_code}" -v -F capabilityTypeZip=@capabilityTypes.zip -H "USER_ID: jh0003" ${HOST_IP}:${HOST_PORT}/sdc2/rest/v1/catalog/uploadType/capability)
37 if [ ${http_code} -eq 201  ]; then
38         echo -e "\n###################### Adding The CapabilityTypes status code:${http_code} End ########################\n\n\n"
39 elif [ ${http_code} -eq 500 ]; then
40         echo -e "\n###################### Failed to add CapabilityTypes status code:${http_code} End ########################\n\n\n"
41         exit 1
42 else
43         echo -e "\n###################### Failed to add CapabilityTypes status code:${http_code} End ########################\n\n\n"
44         exit 1
45 fi
46 #Add The InterfaceLifecycleTypes
47 http_code=$(curl -s -o /dev/null -w "%{http_code}" -v -F interfaceLifecycleTypeZip=@interfaceLifecycleTypes.zip -H "USER_ID: jh0003" ${HOST_IP}:${HOST_PORT}/sdc2/rest/v1/catalog/uploadType/interfaceLifecycle)
48 if [ ${http_code} -eq 201  ]; then
49         echo -e "\n###################### Adding The InterfaceLifecycleTypes status code:${http_code} End ########################\n\n\n"
50 elif [ ${http_code} -eq 409 ]; then
51     echo -e "\n###################### Already exists InterfaceLifecycleTypes status code:${http_code} End ########################\n\n\n"       
52 elif [ ${http_code} -eq 500 ]; then
53         echo -e "\n###################### Failed to add InterfaceLifecycleTypes status code:${http_code} End ########################\n\n\n"
54         exit 1
55 else
56         echo -e "\n###################### Failed to add InterfaceLifecycleTypes status code:${http_code} End ########################\n\n\n"
57         exit 1
58 fi
59 #Add The CategoryTypes
60 http_code=$(curl -s -o /dev/null -w "%{http_code}" -v -F categoriesZip=@categoryTypes.zip -H "USER_ID: jh0003" ${HOST_IP}:${HOST_PORT}/sdc2/rest/v1/catalog/uploadType/categories)
61 if [ ${http_code} -eq 201  ]; then
62         echo -e "\n###################### Adding The CategoryTypes status code:${http_code} End ########################\n\n\n"
63 elif [ ${http_code} -eq 409 ]; then
64     echo -e "\n###################### Already exists CategoryTypes status code:${http_code} End ########################\n\n\n" 
65 elif [ ${http_code} -eq 500 ]; then
66         echo -e "\n###################### Failed to add CategoryTypes status code:${http_code} End ########################\n\n\n"
67         exit 1
68 else
69         echo -e "\n###################### Failed to add CategoryTypes status code:${http_code} End ########################\n\n\n"
70         exit 1
71 fi
72
73 addResource "root"
74 addResource "compute"
75 addResource "softwareComponent"
76 addResource "webServer"
77 addResource "webApplication"
78 addResource "DBMS"
79 addResource "database"
80 addResource "objectStorage"
81 addResource "blockStorage"
82 addResource "containerRuntime"
83 addResource "containerApplication"
84 addResource "loadBalancer"
85 addResource "port"
86 addResource "network"
87
88 exit 0
89