SODALITE-EU / ide

Apache License 2.0
7 stars 4 forks source link

Providing Refactor Information About the Deployed Application #114

Closed IndikaKuma closed 3 years ago

IndikaKuma commented 3 years ago

The refactorer needs to be able to know the information about the deployed application: AADM Id, blueprint id , input file, and deployment id. The refactorer will provide an API.

jesus-gorronogoitia commented 3 years ago

Hi @IndikaKuma Please provide me the REST API (endpoint, HTTP verb, request query) to send to Refactoring requested information. Provide me as well possible responses (success, failure) associated HTTP codes. If you provide me an working example with curl it would be helpful. Thanks.

IndikaKuma commented 3 years ago

About the format of the message (API request), I propose the following. Is it Okay with you? If is OKay, I will implement this at Refactorer, and let you know the endpoint information and access methods/examples

{ "aadm_id": "value", "deployment_id": "value", "blueprint_token": "value", "input": { "key": "value", ...... } }

jesus-gorronogoitia commented 3 years ago

So, a POST message with that JSON payload. Ok, fine with me. Will you adopt IAM communication? If so, in a authentication bearer header, like other Sodalite components? Please, let me know when you have an exposed working prototype to play with

IndikaKuma commented 3 years ago

I will try first without IAM communication.

IndikaKuma commented 3 years ago

Hi Jesus,

Is it possible to provide the aadm file itself? It seems easy to modify aadm (than aadm json).

jesus-gorronogoitia commented 3 years ago

Yes, I can provide you the aadm content, if you prefer, but the aadm json generated by the KB contains the complete information required to generate the blueprint, including the description of resources used by the aadm (that is, the types declared in RMs). Anyway, I can provide you the the aadm and/or the aadm json. But in this case, the POST message sent should be a multpart url enconded, with one part for the aadm, another part for the inputs, and you can encode the deployment_id and blueprint_id in the URL query

IndikaKuma commented 3 years ago

Thanks. I will have multi-part API method. I think modifying (refactoring) AADM is much simpler compared with modifying AADM JOSN. Also, I can save the modified AASM in the KB and get AADM json (Like IDE does).

IndikaKuma commented 3 years ago

1) Providing AADM and blueprint information.

Note: I will send you the IP address of the refactoer at ATOS testbed via slack.

http://localhost:8080/rule-based-refactorer/v0.1/api/{app_id}/deployments/

app_id - the name of the application (any unique name) inputs - is the content of the input file as a string. In the vehicle IoT example, there is no input.

curl --request POST \ --url http://localhost:8080/rule-based-refactorer/v0.1/api/vehicleiot/deployments/ \ --header 'Content-Type: application/json' \ --data '{ "aadm_id":"https://www.sodalite.eu/ontologies/workspace/1/7ke93c8pgi7piknhgaat0q1n00/AADM_9gfoiqlpkkuh4thirvufqr2kl2", "blueprint_id":"51d1671d-c9f5-418d-b19f-94437f5460ac", "deployment_id":"612efea0-c666-42de-9803-5adce8d59eac", "inputs": "" }'

2) Updating the refactoring rule set. There is a default rule file. You can use it for testing. https://github.com/SODALITE-EU/refactoring-ml/blob/master/rule-based/src/main/resources/rules/refactoring.drl

http://localhost:8080/rule-based-refactorer/v0.1/api/{app_id}/rules

curl --request PUT \ --url http://localhost:8080/rule-based-refactorer/v0.1/api/vehicleiot/rules \ --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \ --form 'file=@C:\Users\iweerasi\Downloads\refactoring.drl'

3) Sending an Alert (this is to be used by the Prometheus Alert manager)

http://localhost:8080/rule-based-refactorer/v0.1/{app_id}/vehicleiot/alerts

curl --request POST \ --url http://localhost:8080/rule-based-refactorer/v0.1/api/vehicleiot/alerts \ --header 'Content-Type: application/json' \ --data '{"receiver":"default-receiver","status":"firing","alerts":[{"status":"firing","labels":{"alertname":"HostHighCpuLoad","instance":"154.48.185.159:9100","severity":"warning"},"annotations":{"description":"CPU load is \u003e 80%\n VALUE = 81.29999999999806\n LABELS: map[instance:154.48.185.159:9100]","summary":"Host high CPU load (instance 154.48.185.159:9100)"},"startsAt":"2020-08-21T10:57:27.287074165Z","endsAt":"0001-01-01T00:00:00Z","generatorURL":"http://154.48.185.213/graph?g0.expr=100+-+%28avg+by%28instance%29+%28irate%28node_cpu_seconds_total%7Bmode%3D%22idle%22%7D%5B5m%5D%29%29+%2A+100%29+%3E+80\\u0026g0.tab=1","fingerprint":"44ed747b85e76fff"}],"groupLabels":{"alertname":"HostHighCpuLoad"},"commonLabels":{"alertname":"HostHighCpuLoad","instance":"154.48.185.159:9100","os_id":"vehicle-iot-demo-v1","severity":"warning"},"commonAnnotations":{"description":"CPU load is \u003e 80%\n VALUE = 81.29999999999806\n LABELS: map[instance:154.48.185.159:9100]","summary":"Host high CPU load (instance 154.48.185.159:9100)"},"externalURL":"http://154.48.185.213:9093","version":"4","groupKey":"d","truncatedAlerts":0}'

jesus-gorronogoitia commented 3 years ago

I assume IDE only worries about the first API, doesn't it?

IndikaKuma commented 3 years ago

Yes. But if the user develops the rules (with Drools Eclipse Plugin) and he/she may want to set it via the IDE.

jesus-gorronogoitia commented 3 years ago

@IndikaKuma what are the possible HTTP code responses and body response content of the first API?: http://localhost:8080/rule-based-refactorer/v0.1/api/%7Bapp_id%7D/deployments/

IndikaKuma commented 3 years ago

200 and 500

jesus-gorronogoitia commented 3 years ago

so, no body response I need to parse, just to confirm HTTP_OK (200) response, right?

IndikaKuma commented 3 years ago

HTTP_OK (200) - Yes. A message (string) is returned for both 200 and 500. But, you do not need to parse it. May be just a display.

jesus-gorronogoitia commented 3 years ago

I have a doubt, you request a unique application name, but it could be the case multiple deployments of the same application (same name) are deployed. In this case, aadm_id is also common to all those deployments, so only the deployment_id and blueprint_id would be unique, but not the application name and aadm_id. So, if you need a unique application name I can concatenate the application-name (i.e. snow) with the deployment_id What do you want me to do?

jesus-gorronogoitia commented 3 years ago

considering your example of API endpoint: http://localhost:8080/rule-based-refactorer/v0.1/api/vehicleiot/deployments/ I assume the app name (i.e. vehicleiot) does not need to be unique among multiple invocations of this API, so new deployments are added to that app

IndikaKuma commented 3 years ago

You can call the API with the same app name but with different deployment information. The current implementation simply replaces the existing deployment information.

jesus-gorronogoitia commented 3 years ago

Hi @IndikaKuma When testing the Refactorer API with this curl command: curl --request POST --url http://192.168.2.166:8080/rule-based-refactorer/v0.1/api/snow/deployments/ --header 'Content-Type: application/json' --data '{ "inputs": { "image-name": "centos-node_exporter", "mysql-db-pass": "somepassword", "docker-network": "snow", "docker-registry-url": "154.48.185.207", "flavor-name": "m1.medium", "security-groups": "default,remote_access,snow", "demo-files-path": "/demo", "env": null, "docker-registry-cert-country-name": "SI", "docker-registry-cert-organization-name": "XLAB", "docker-registry-cert-email-address": "some@xlab.si", "mysql-env": { "MYSQL_DATABASE": "wc_crawler_db", "MYSQL_ROOT_PASSWORD": "somepassword" }, "ssh-key-name": "154-48-185-209-xOpera", "openstack-network-name": "orchestrator-network", "username": "yosu" }, "aadm_id": "https\\://www.sodalite.eu/ontologies/workspace/1/vbeit9auui3d3j0tdekbljfndl/AADM_92aj0uo7t6l6u8mv5tmh99pjnb", "blueprint_id": "51d1671d-c9f5-418d-b19f-94437f5460ac", "deployment_id": "612efea0-c666-42de-9803-5adce8d59eac" }'

I get a 400 Bad Request with this message:

Cannot deserialize instance of java.lang.String out of START_OBJECT token at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 2, column: 13] (through reference chain: nl.jads.sodalite.dto.DeploymentInfo["inputs"])

Same result when I invoke the Refactorer API from the IDE. What is the correct way to encode the request JSON body?

jesus-gorronogoitia commented 3 years ago

Fixed, using inputs yaml

jesus-gorronogoitia commented 3 years ago

Implementation pushed in commit https://github.com/SODALITE-EU/ide/commit/93f31ee3aa4c980c8824eedbaea98d2403f953a5 Pending of tested by UCs during the deployment process

IndikaKuma commented 3 years ago

Thanks

jesus-gorronogoitia commented 3 years ago

reported to Refactoring upon successful deployment tested and confirmed by @IndikaKuma Closing issue