Commit 50b04be1 authored by skoulouzis's avatar skoulouzis Committed by GitHub

Merge pull request #31 from skoulouzis/package

Package
parents ad7aecb4 f63cf846
/drip-commons/target/
/drip-api/target/
/drip-planner/target/
/drip-commons/nbproject/
/drip-simple_planner/target/
/drip-provisioner/target/
/target/
/drip-planner2provisioner/target/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
#-------------------------Dockers--------------------------------------------
docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management
docker run --name mongo-inst -p 127.0.0.1:27017:27017 -d mongo:3
version: '3'
services:
input:
container_name: InputDistributor
ports:
- "2000:2000/udp"
environment:
- inPort=2000
- multicastAddrIP=225.2.2.0
- multicastAddrPort=3000
- waitingTime=1000
- videoWidth=176
- videoHeight=100
image: 145.100.133.241:5000/mogswitch/inputdistributor
input2:
container_name: InputDistributor2
ports:
- "2002:2002/udp"
environment:
- inPort=2002
- multicastAddrIP=225.2.2.2
- multicastAddrPort=3002
- waitingTime=1000
- videoWidth=176
- videoHeight=100
image: 145.100.133.241:5000/mogswitch/inputdistributor
proxy:
container_name: ProxyTranscoder
ports:
- "8081:80"
environment:
- multicastAddrIP=225.2.2.0
- multicastAddrPort=3000
- videoWidth=176
- videoHeight=100
image: 145.100.133.241:5000/mogswitch/proxytranscoder
privileged: true
proxy2:
container_name: ProxyTranscoder2
ports:
- "8082:80"
environment:
- multicastAddrIP=225.2.2.2
- multicastAddrPort=3002
- videoWidth=176
- videoHeight=100
image: 145.100.133.241:5000/mogswitch/proxytranscoder
privileged: true
proxyOut:
container_name: ProxyTranscoderOut
ports:
- "8085:80"
environment:
- multicastAddrIP=226.2.2.2
- multicastAddrPort=6000
- videoWidth=176
- videoHeight=100
image: 145.100.133.241:5000/mogswitch/proxytranscoder
privileged: true
switcher:
container_name: VideoSwitcher
ports:
- "8008:8008"
environment:
# PROXY 1
- multicastAddrIP=225.2.2.0
- multicastAddrPort=3000
# PROXY 2
- multicastAddrIP2=225.2.2.2
- multicastAddrPort2=3002
# SWITCHER SETTINGS
- switcherOutAddrIP=226.2.2.2
- switcherOutAddrPort=6000
- switcherREST=8008
- waitingTime=1000
- videoWidth=176
- videoHeight=100
image: 145.100.133.241:5000/mogswitch/videoswitcher
output:
container_name: OutputTranscoder
ports:
- "4000:4000"
environment:
- multicastAddrIP=226.2.2.2
- multicastAddrPort=6000
- videoWidth=176
- videoHeight=100
- OutIP=192.168.1.194
- OutPort=4000
image: 145.100.133.241:5000/mogswitch/outputtranscoder
privileged: true
This diff is collapsed.
{
"key": "AKISAKISAKIS",
"keyIdAlias": "6J76J76J76J76J76J76J7",
"logineKys": [
{
"attributes": {
"domain_name ": "California"
},
"type": "PUBLIC",
"key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA3Tz2mr7SZiAMfQyuvBjM9Oi..Z1BjP5CE/Wm/Rr500P\nRK+Lh9x5eJPo5CAZ3/ANBE0sTK0ZsDGMak2m1g7..3VHqIxFTz0Ta1d+NAj\nwnLe4nOb7/eEJbDPkk05ShhBrJGBKKxb8n104o/..PdzbFMIyNjJzBM2o5y\n5A13wiLitEO7nco2WfyYkQzaxCw0AwzlkVHiIyC..71pSzkv6sv+4IDMbT/\nXpCo8L6wTarzrywnQsh+etLD6FtTjYbbrvZ8RQM..Hg2qxraAV++HNBYmNW\ns0duEdjUbJK+ZarypXI9TtnS4o1Ckj7POfljiQI..IBAFyidxtqRQyv5KrD\nkbJ+q+rsJxQlaipn2M4lGuQJEfIxELFDyd3XpxP..Un/82NZNXlPmRIopXs\n2T91jiLZEUKQw+n73j26adTbteuEaPGSrTZxBLR..yssO0wWomUyILqVeti\n6AkL0NJAuKcucHGqWVgUIa4g1haE0ilcm6dWUDo..fd+PpzdCJf1s4NdUWK\nYV2GJcutGQb+jqT5DTUqAgST7N8M28rwjK6nVMI..BUpP0xpPnuYDyPOw6x\n4hBt8DZQYyduzIXBXRBKNiNdv8fum68/5klHxp6..4HRkMUL958UVeljUsT\nBFQlO9UCgYEA/VqzXVzlz8K36VSTMPEhB5zBATV..PRiXtYK1YpYV4/jSUj\nvvT4hP8uoYNC+BlEMi98LtnxZIh0V4rqHDsScAq..VyeSLH0loKMZgpwFEm\nbEIDnEOD0nKrfT/9K9sPYgvB43wsLEtUujaYw3W..Liy0WKmB8CgYEA34xn\n1QlOOhHBn9Z8qYjoDYhvcj+a89tD9eMPhesfQFw..rsfGcXIonFmWdVygbe\n6Doihc+GIYIq/QP4jgMksE1ADvczJSke92ZfE2i..fitBpQERNJO0BlabfP\nALs5NssKNmLkWS2U2BHCbv4DzDXwiQB37KPOL1c..kBHfF2/htIs20d1UVL\n+PK+aXKwguI6bxLGZ3of0UH+mGsSl0mkp7kYZCm..OTQtfeRqP8rDSC7DgA\nkHc5ajYqh04AzNFaxjRo+M3IGICUaOdKnXd0Fda..QwfoaX4QlRTgLqb7AN\nZTzM9WbmnYoXrx17kZlT3lsCgYEAm757XI3WJVj..WoLj1+v48WyoxZpcai\nuv9bT4Cj+lXRS+gdKHK+SH7J3x2CRHVS+WH/SVC..DxuybvebDoT0TkKiCj\nBWQaGzCaJqZa+POHK0klvS+9ln0/6k539p95tfX..X4TCzbVG6+gJiX0ysz\nYfehn5MCgYEAkMiKuWHCsVyCab3RUf6XA9gd3qY..fCTIGtS1tR5PgFIV+G\nengiVoWc/hkj8SBHZz1n1xLN7KDf8ySU06MDggB..hJ+gXJKy+gf3mF5Kmj\nDtkpjGHQzPF6vOe907y5NQLvVFGXUq/FIJZxB8k..fJdHEm2M4=\n-----END RSA PRIVATE KEY-----"
},
{
"attributes": {
"domain_name ": "Virginia"
},
"type": "PUBLIC",
"key": "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----END RSA PRIVATE KEY-----"
}
],
"cloudProviderName": "ec2"
}
{
"key": "my_secret_password",
"keyIdAlias": "geni",
"logineKys": [
{
"attributes": null,
"key": "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu\nERwta7+fWIfxOo208ett/jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi/2A\n+xTBtWdEo7XGUujKDvC2/aZKukfjpOiUI8AhLAfjmlcD/UZ1QPh0mHsglRNCmpCw\nmwSXA9VNmhz+PiB+Dml4WWnKW/VHo2ujTXxq7+efMU4H2fny3Se3KYOsFPFGZ1TN\nQSYlFuShWrHPtiLmUdPoP6CV2mML1tk+l7DIIqXrQhLUKDACeM5roMx0kLhUWB8P\n+0uj1CNlNN4JRZlC7xFfqiMbFRU9Z4N6YwIDAQAB\n-----END RSA PUBLIC KEY-----",
"type": "PUBLIC"
},
{
"attributes": null,
"key": "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----END RSA PRIVATE KEY-----",
"type": "PRIVATE"
}
],
"cloudProviderName": "exogeni"
}
{"creationDate":1488794695660,"parameters":[{"name":"com.amazonaws.AmazonServiceException","encoding":"UTF-8","value":"The maximum number of VPCs has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: VpcLimitExceeded; Request ID: e854939e-5386-46f3-baa8-4e3c425b98ee)"}]}
\ No newline at end of file
{"creationDate":1488801250836,"parameters":[{"name":"2e5dafb6-5a1c-4a66-9dca-5841f99ea735","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-7642741842514/user.pem\nuserName: zh9314\nsubnets:\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-7642741842514/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: master\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 54.236.125.129\n instanceId: i-01067856cdd3be521\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-7642741842514/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: slave\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 54.236.125.129\n instanceId: i-01067856cdd3be521\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"54.236.125.129 ubuntu /tmp/Input-7642741842514/Virginia.pem master\n54.236.125.129 ubuntu /tmp/Input-7642741842514/Virginia.pem slave\n"}]}
\ No newline at end of file
{"creationDate":1488805337447,"parameters":[{"name":"2e5dafb6-5a1c-4a66-9dca-5841f99ea735","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-11594765342486/user.pem\nuserName: zh9314\nsubnets:\n\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-11594765342486/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: master\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 34.207.73.18\n instanceId: i-0e82b5624a0df99b1\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 8fcc1788d9ee462c826572c79fdb2a6a\n type: Switch.nodes.Compute\n nodeType: t2.medium\n OStype: Ubuntu 16.04\n script: /tmp/Input-11594765342486/guiscipt.sh\n domain: ec2.us-east-1.amazonaws.com\n installation: null\n clusterType: swarm\n role: slave\n dockers: mogswitch/ProxyTranscoder:1.0\n public_address: 34.207.73.18\n instanceId: i-0e82b5624a0df99b1\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem master\n34.207.73.18 ubuntu /tmp/Input-11594765342486/Virginia.pem slave\n"}]}
\ No newline at end of file
{"creationDate":1488808559406,"parameters":[{"name":"2e5dafb6-5a1c-4a66-9dca-5841f99ea735","encoding":"UTF-8","value":"publicKeyPath:/tmp/Input-14773430542445/user.pem\nuserName:zh9314\nsubnets:\n-{name:s1,subnet:192.168.10.0,netmask:255.255.255.0}\ncomponents:\n-name:8fcc1788d9ee462c826572c79fdb2a6a\ntype:Switch.nodes.Compute\nnodeType:t2.medium\nOStype:Ubuntu16.04\nscript:/tmp/Input-14773430542445/guiscipt.sh\ndomain:ec2.us-east-1.amazonaws.com\ninstallation:null\nclusterType:swarm\nrole:master\ndockers:mogswitch/ProxyTranscoder:1.0\npublic_address:52.73.245.157\ninstanceId:i-0aea14557986d25d0\nethernet_port:\n-{name:p1,subnet_name:s1,address:192.168.10.10}\n-name:8fcc1788d9ee462c826572c79fdb2a6a\ntype:Switch.nodes.Compute\nnodeType:t2.medium\nOStype:Ubuntu16.04\nscript:/tmp/Input-14773430542445/guiscipt.sh\ndomain:ec2.us-east-1.amazonaws.com\ninstallation:null\nclusterType:swarm\nrole:slave\ndockers:mogswitch/ProxyTranscoder:1.0\npublic_address:52.73.245.157\ninstanceId:i-0aea14557986d25d0\nethernet_port:\n-{name:p1,subnet_name:s1,address:192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"52.73.245.157ubuntu/tmp/Input-14773430542445/Virginia.pemmaster\n52.73.245.157ubuntu/tmp/Input-14773430542445/Virginia.pemslave\n"}]}
\ No newline at end of file
{
"creationDate": 1487002029722,
"parameters": [
{
"url": null,
"encoding": "UTF-8",
"value": {"cloud profile" :{ "cloud platform" :{ "identifier" : "cp001", "name" : "Mock ExoGENI", "description" : "Networked virtual infrastructure cloud platform ExoGENI.", "provides cloud" :[ { "identifier" : "cloud001", "name" : "ExoGENI Boston", "description" : "ExoGENI's Boston rack.", "domain" : "Boston", "end-point" : "r0.boston.exogeni.com", "provides VM" :[ "vm_type001", "vm_type002" ] }, { "identifier" : "cloud002", "name" : "ExoGENI Washington", "description" : "ExoGENI's Washington rack.", "domain" : "Washington", "end-point" : "r0.washington.exogeni.com", "provides VM" :[ "vm_type001", "vm_type002" ] } ], "accessed via" : "switch_default_broker" }, "virtual machines types" :[ { "identifier" : "ExoSmall", "name" : "ExoGENI small VM", "description" : "A small virtual machine with 1Ghz CPU and 512MB RAM.", "has property assignment" :[ { "assignment" : 1.0, "assigns to property" : "CpuClockSpeedProperty", "measured in unit" : "GigahertzUnit" }, { "assignment" : 512, "assigns to property" : "MemoryProperty", "measured in unit" : "MegaBytesUnit" } ], "allows VM image" :[ "vm_image_ubuntu0" ] }, { "identifier" : "ExoMedium", "name" : "ExoGENI medium VM", "description" : "A medium virtual machine with 3GHz CPU and 2GB RAM.", "has property assignment" :[ { "assignment" : 3.0, "assigns to property" : "CpuClockSpeedProperty", "measured in unit" : "GigahertzUnit" }, { "assignment" : 2, "assigns to property" : "MemoryProperty", "measured in unit" : "GigaBytesUnit" } ], "allows VM image" :[ "vm_image_ubuntu0", "vm_image_debian0" ] } ], "virtual machine images" :[ { "identifier" : "vm_image_ubuntu0", "name" : "Ubuntu 14.04 install image", "description" : "A VM image with Ubuntu 14.04 pre-installed.", "operating system" : "Ubuntu 14.04" }, { "identifier" : "vm_image_debian0", "name" : "Debian 8.0 install image", "description" : "A VM image with Debian 8.0 pre-installed.", "operating system" : "Debian 8.0" } ] }},
"name": "profile",
"attributes": null
}
]
}
{
"creationDate": 1487002029722,
"parameters": [
{
"url": null,
"encoding": null,
"value": "33000",
"name": "input",
"attributes": null
},
{
"url": null,
"encoding": "UTF-8",
"value": "0.84\n 0.735\n 0.44\n 0.211\n 0.669\n 0.683\n 0.011\n 0.435\n 0.246\n 0.006\n 0.046\n 0.214\n 0.872\n 0.206\n 0.643\n 0.289\n 0.381\n 0.05\n 0.831\n 0.835\n 0.953\n 0.119\n 0.214\n 0.412\n 0.643\n 0.714\n 0.672\n 0.929\n 0.562\n 0.216\n 0.386\n 0.309\n 0.977\n 0.281\n 0.522\n 0.393\n 0.217\n 0.002\n 0.147\n 0.755\n 0.745\n 0.074\n 0.032\n 0.844\n 0.636\n 0.74\n 0.473\n 0.539\n 0.032\n 0.268\n 0.736\n 0.232\n 0.278\n 0.309\n 0.143\n 0.171\n 0.491\n 0.55\n 0.087\n 0.723\n 0.274\n 0.757\n 0.263\n 0.09\n 0.563\n 0.747\n 0.935\n 0.493\n 0.108\n 0.448\n 0.128\n 0.498\n 0.691\n 0.791\n 0.499\n 0.474\n 0.045\n 0.338\n 0.754\n 0.838\n 0.758\n 0.8\n 0.055\n 0.798\n 0.517\n 0.619\n 0.055\n 0.803\n 0.467\n 0.47\n 0.842\n 0.294\n 0.977\n 0.211\n 0.513\n 0.282\n 0.147\n 0.219\n 0.445\n 0.157\n\n",
"name": "someInputFile",
"attributes": null
},
{
"url": "http://www.gutenberg.org/cache/epub/3160/pg3160.txt",
"encoding": null,
"value": null,
"name": "theNameOfTheParamater",
"attributes": {
"level": "0",
"filename":"file.txt"
}
}
]
}
{
"creationDate": 1487002029722,
"parameters": [
{
"url": null,
"encoding": "UTF-8",
"value": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA8XXU0BSmjVxDWT23di1++beDDCiZkFHw+uQ/fyF3j4LSg+LRoE7NZkvrh\n056jlYGbK6lt/p5kPAI8SDPH/eHU2pAhK40StSvJHX1lnNDLBy7bDfwaUru3ZkOL2jf2M5Z9/PdE\n7RxWb9Vn3/jrW6ojRt29EQcIKwgxJPd4KrrKSwu5HifmxIFFY4DvSBt+/M0pPCj2fJdZ0x9X7yMM\n+f1uvYjXfwJKd5oT2h0pyXSl9golvtVkiVMHcU3jNjX4meG9RHdteRu9dSmtDxFHVd98cJMInScA\nxw3hP9NQ8lc9v5eiwFc2B52rlE1Hwh5mdJzA0pin/7aKKd9/Mv8/cQIDAQABAoIBAQCCJEtGt8OY\n4X1rQPTxrLqbE0i1Ok6FWvnYHLtFzauE+C4Jf/G++qWZ8LHXyYcMI1XyEAANgW16re5CdcX9+ILT\ncPPjtYlbStcJdQcZ8OtioRq8zWFd4UJi0zBfWwq23DDDz1oqjS/GSN7BuhkZm7VnG4WV/Y+Y7NxX\nLTwnu4Y2KJk1PCXCORjNOhm6AM+56/nG8v5ds7rwfYkZuVJB86xj4vvgogPsydxush7pSJmor\nBih/2jNTYW1Xq5G7ixLB+qlf80tAZ22yRjnGZvyILl\nvrGs7T6Q0ncKZYldP/Cxu7H9SEs9AoGBAPv8mDUTkba6e4RCdtjntrQesSYEL5a04AFDhOrPlGxb\nQo6SHGl8FDv5xJVr33GdzjOajpvHfBLbm7JmCZA5jOpMCaRdR5oDzEM3mZYTvnlQfyaege40ayp0\nCaRFZBI7CoRC4yqbCNPvWYJ8gudLHfheYURz8HHMt7dT6IxYcz6DAoGBAPVOUXXVcUigks+Z83/M\nl6R0+RehKYdKl/XdK0tzKeaJ9qWOL0eEpIekJow9U1FYYhCuUWnJpEcUI2K/hmGeX4HOOLltuQZu\ncTajjIJaz5DKgIJIApghxRfKA3Ka3IjsMLi+uF4F+GbAInSFpHK3cFzSs2q1dlgVFUp6cQ4NqSf7\nAoGADcm6glz5wifeDlScsCaWzGUE+GCssP5u21Jbr6+LoYVd0upUA1wWxe\n66E8mbxflZawkTlr5aR9AH5otNzb+IxIBddTvcc6kNApdP84b9akLSMx5h7K00/8YaxdF3i8qO9B\nSo/PfrFhXLi47L0YomVMmQUCgYEAuzEfspbFktGOFsP5b+3VTldA+kouoaJHogQ7lKD2OYnQYPfG\nloHe9+9Ixz3JBcs3UlljoSGRr3XEiuRrJSElvlXuUFzm16Hhs9xi7\n7/SlHWXU1VMjAm3eHSMaobvgD8VtAMMnlZnqD8pVfL\n70wyYNRfSnwq9i7uPDSMOVlnAlMgRXO8rqursoBOz+SBaG2uuwtBkrFmmmxBP/IZs0g2OQbMnvkB\nmUbKa7m1ZAnqlsE7FIO073FWlXSg90bTLMWSEhMWgKFpf0dgT/iX93yjhySmzew1Msl7Kw==\n-----END RSA PRIVATE KEY-----",
"name": "credential",
"attributes": {
"IP": "145.100.100",
"user":"root",
"role":"master"
}
},
{
"url": null,
"encoding": "UTF-8",
"value": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA8XXU0BSmjVxDWT23di1++beDDCiZkFHw+uQ/fyF3j4LSg+LRoE7NZkvrh\n056jlYGbK6lt/p5kPAI8SDPH/eHU2pAhK40StSvJHX1lnNDLBy7bDfwaUru3ZkOL2jf2M5Z9/PdE\n7RxWb9Vn3/jrW6ojRt29EQcIKwgxJPd4KrrKSwu5HifmxIFFY4DvSBt+/M0pPCj2fJdZ0x9X7yMM\n+f1uvYjXfwJKd5oT2h0pyXSl9golvtVkiVMHcU3jNjX4meG9RHdteRu9dSmtDxFHVd98cJMInScA\nxw3hP9NQ8lc9v5eiwFc2B52rlE1Hwh5mdJzA0pin/7aKKd9/Mv8/cQIDAQABAoIBAQCCJEtGt8OY\n4X1rQPTxrLqbE0i1Ok6FWvnYHLtFzauE+C4Jf/G++qWZ8LHXyYcMI1XyEAANgW16re5CdcX9+ILT\ncPPjtYlbStcJdQcZ8OtioRq8zWFd4UJi0zBfWwq23DDDz1oqjS/GSN7BuhkZm7VnG4WV/Y+Y7NxX\nLTwnu4Y2KJk1PCXCORjNOhm6AM+56/nG8v5ds7rwfYkZuVJB86xj4vvgogPsydxush7pSJmor\nBih/2jNTYW1Xq5G7ixLB+qlf80tAZ22yRjnGZdYLtHX01CsdioJZn2Z0KsP3LCmuPIHr39DvyILl\nvrGs7T6Q0ncKZYldP/Cxu7H9SEs9AoGBAPv8mDUTkba6e4RCdtjntrQesSYEL5a04AFDhOrPlGxb\nQo6SHGl8FDv5xJVr33GdzjOajpvHfBLbm7JmCZA5jOpMCaRdR5oDzEM3mZYTvnlQfyaege40ayp0\nCaRFZBI7CoRC4yqbCNPvWYJ8gudLHfheYURz8HHMt7dT6IxYcz6DAoGBAPVOUXXVcUigks+Z83/M\nl6R0+RehKYdKl/XdK0tzKeaJ9qWOL0eEpIekJow9U1FYYhCuUWnJpEcUI2K/hmGeX4HOOLltuQZu\ncTajjIJaz5DKgIJIApghxRfKA3Ka3IjsMLi+uF4F+GbAInSFpHK3cFzSs2q1dlgVFUp6cQ4NqSf7\nAoGADcm6glz5wifeDlScsC2tn5l2VAAyompvP2J0aWzGUE+GCssP5u21Jbr6+LoYVd0upUA1wWxe\n66E8mbxflZawkTlr5aR9AH5otNzb+IxIBddTvcc6kNApdP84b9akLSMx5h7K00/8YaxdF3i8qO9B\nSo/PfrFhXLi47L0YomVMmQUCgYEAuzEfspbFktGOFsP5b+3VTldA+kouoaJHogQ7lKD2OYnQYPfG\nloHe9+9Ixz3JBcs3UlljoSGRr3XEiuRrJSElvlXuUFzm16Hhs9xi7\n7/SlHWXU1VMjAm3eHSMaobvgD8VtyqFdBMxZ6fLTsRC1o98CgYB4K6q7GffLL9AMMnlZnqD8pVfL\n70wyYNRfSnwq9i7uPDSMOVlnAlMgRXO8rqursoBOz+SBaG2uuwtBkrFmmmxBP/IZs0g2OQbMnvkB\nmUbKa7m1ZAnqlsE7FIO073FWlXSg90bTLMWSEhMWgKFpf0dgT/iX93yjhySmzew1Msl7Kw==\n-----END RSA PRIVATE KEY-----",
"name": "credential",
"attributes": {
"IP": "145.200.100",
"user":"root",
"tole":"slave"
}
}
]
}
{
"creationDate": 1487002029722,
"parameters": [
{
"url": null,
"encoding": "UTF-8",
"value": {"topology_template": {"node_templates": {"2d13d708e3a9441ab8336ce874e08dd1": {"artifacts": {"docker_image": {"type": "tosca.artifacts.Deployment.Image.Container.Docker", "file": "mogswitch/InputDistributor:1.0", "repository": "MOG_docker_hub"}}, "interfaces": {"Standard": {"create": {"implementation": "docker_image", "inputs": {"port_bindings": ["2000:2000", "3000:3000"], "command": "InputDistributor", "exported_ports": [2000]}}}}, "type": "Switch.nodes.Application.Container.Docker.MOG.InputDistributor", "properties": {"waitingTime": 5, "multicastAddrIP": "255.2.2.0", "QoS": {"response_time": "30ms"}, "multicastAddrPort": 3000, "videoWidth": 176, "inPort": 2000, "videoHeight": 100}}, "8fcc1788d9ee462c826572c79fdb2a6a": {"artifacts": {"docker_image": {"type": "tosca.artifacts.Deployment.Image.Container.Docker", "file": "mogswitch/ProxyTranscoder:1.0", "repository": "MOG_docker_hub"}}, "interfaces": {"Standard": {"create": {"implementation": "docker_image", "inputs": {"port_bindings": ["8080:80"], "command": "ProxyTranscoder", "exported_ports": [80]}}}}, "type": "Switch.nodes.Application.Container.Docker.MOG.ProxyTranscoder", "properties": {"multicastAddrIP": "255.2.2.0", "multicastAddrPort": 3000, "QoS": {"response_time": "30ms"}, "videoWidth": 176, "videoHeight": 100}}, "5e0add703c8a43938a39301f572e46c0": {"type": "Switch.nodes.Application.Connection", "properties": {"latency": "30ms", "bandwidth": "130MB/s", "multicast": {"multicastAddrIP": "255.2.2.0", "multicastAddrPort": 3000}, "jitter": "500ms", "target": {"netmask": "255.255.255.0", "address": "192.168.21.12", "port_name": "proxyTranscoder_in", "component_name": "8fcc1788d9ee462c826572c79fdb2a6a"}, "source": {"netmask": "255.255.255.0", "address": "192.168.21.11", "port_name": "inputDistributor_out", "component_name": "2d13d708e3a9441ab8336ce874e08dd1"}}}}}, "artifact_types": {"tosca.artifacts.Deployment.Image.Container.Docker": {"derived_from": "tosca.artifacts.Deployment.Image"}}, "data_types": {"Switch.datatypes.Application.Connection.Multicast": {"properties": {"multicastAddrIP": {"type": "string"}, "multicastAddrPort": {"type": "integer"}}, "derived_from": "tosca.datatypes.Root"}, "Switch.datatypes.Application.Connection.EndPoint": {"properties": {"netmask": {"type": "string"}, "address": {"type": "string"}, "port_name": {"type": "string"}, "component_name": {"type": "string"}}, "derived_from": "tosca.datatypes.Root"}, "Switch.datatypes.Network.EndPoint": {"properties": {"netmask": {"type": "string"}, "port_name": {"type": "string"}, "host_name": {"type": "string"}, "address": {"type": "string"}}, "derived_from": "tosca.datatypes.Root"}, "Switch.datatypes.QoS.AppComponent": {"properties": {"response_time": {"type": "string"}}, "derived_from": "tosca.datatypes.Root"}, "Switch.datatypes.Network.Multicast": {"properties": {"multicastAddrIP": {"type": "string"}, "multicastAddrPort": {"type": "integer"}}, "derived_from": "tosca.datatypes.Root"}}, "description": "example file for infrastructure planner", "node_types": {"Switch.nodes.Network": {"properties": {"latency": {"type": "string"}, "bandwidth": {"type": "string"}, "multicast": {"type": "Switch.datatypes.Network.Multicast"}, "jitter": {"type": "string"}, "target": {"type": "Switch.datatypes.Network.EndPoint"}, "source": {"type": "Switch.datatypes.Network.EndPoint"}}, "derived_from": "tosca.nodes.network.Network"}, "Switch.nodes.Application.Connection": {"properties": {"latency": {"type": "string"}, "bandwidth": {"type": "string"}, "multicast": {"type": "Switch.datatypes.Application.Connection.Multicast"}, "jitter": {"type": "string"}, "target": {"type": "Switch.datatypes.Application.Connection.EndPoint"}, "source": {"type": "Switch.datatypes.Application.Connection.EndPoint"}}, "derived_from": "tosca.nodes.Root"}, "Switch.nodes.Compute": {"properties": {"domain": {"type": "string"}, "nodetype": {"type": "string"}, "script": {"type": "string"}, "public_address": {"type": "string"}, "OStype": {"type": "string"}, "ssh_credential": {"type": "tosca.datatypes.Credential"}, "ethernet_port": {"entry_schema": {"type": "tosca.datatypes.network.NetworkInfo"}, "type": "list"}, "installation": {"type": "string"}}, "derived_from": "tosca.nodes.Compute"}, "Switch.nodes.Application.Container.Docker": {"artifacts": {"docker_image": {"type": "tosca.artifacts.Deployment.Image.Container.Docker"}}, "interfaces": {"Standard": {"create": {"inputs": {"port_bindings": {"entry_schema": {"type": "string"}, "type": "list"}, "command": {"type": "string"}, "exported_ports": {"entry_schema": {"type": "string"}, "type": "list"}}}}}, "properties": {"QoS": {"type": "Switch.datatypes.QoS.AppComponent"}}, "derived_from": "tosca.nodes.Container.Application"}, "Switch.nodes.Application.Container.Docker.MOG.InputDistributor": {"artifacts": {"docker_image": {"type": "tosca.artifacts.Deployment.Image.Container.Docker", "file": "mogswitch/InputDistributor:1.0", "repository": "MOG_docker_hub"}}, "properties": {"QoS": {"type": "Switch.datatypes.QoS.AppComponent"}, "multicastAddrPort": {"type": "integer"}, "inPort": {"type": "integer"}, "waitingTime": {"type": "integer"}, "multicastAddrIP": {"type": "string"}, "videoWidth": {"type": "integer"}, "videoHeight": {"type": "integer"}}, "derived_from": "Switch.nodes.Application.Container.Docker"}, "Switch.nodes.Application.Container.Docker.MOG.ProxyTranscoder": {"artifacts": {"docker_image": {"type": "tosca.artifacts.Deployment.Image.Container.Docker", "file": "mogswitch/ProxyTranscoder:1.0", "repository": "MOG_docker_hub"}}, "properties": {"QoS": {"type": "Switch.datatypes.QoS.AppComponent"}, "multicastAddrPort": {"type": "integer"}, "multicastAddrIP": {"type": "string"}, "videoWidth": {"type": "integer"}, "videoHeight": {"type": "integer"}}, "derived_from": "Switch.nodes.Application.Container.Docker"}}, "tosca_definitions_version": "tosca_simple_yaml_1_0", "repositories": {"MOG_docker_hub": {"url": "https://github.com/switch-project/mog", "credential": {"token_type": "X-Auth-Token", "token": "604bbe45ac7143a79e14f3158df67091", "protocol": "xauth"}, "description": "MOG project\u2019s code repository in GitHub"}}}
,
"attributes": null
}
]
}
\ No newline at end of file
{
"creationDate": 1487002029722,
"parameters": [
{
"url": null,
"encoding": "UTF-8",
"value": {u'2d13d708e3a9441ab8336ce874e08dd1': 'Small', u'8fcc1788d9ee462c826572c79fdb2a6a': 'Small', u'5e0add703c8a43938a39301f572e46c0': 'Small'},
"attributes": null
}
]
}
\ No newline at end of file
{"creationDate":1488368936945,"parameters":[{"name":"f293ff03-4b82-49e2-871a-899aadf821ce","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-4007028381500/user.pem\nuserName: zh9314\nsubnets:\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: faab6756-61b6-4800-bffa-ae9d859a9d6c\n type: Switch.nodes.Compute\n nodetype: t2.medium\n OStype: Ubuntu 16.04\n domain: ec2.us-east-1.amazonaws.com\n script: /tmp/Input-4007028381500/guiscipt.sh\n installation: null\n role: master\n dockers: mogswitch/InputDistributor\n public_address: 54.144.0.91\n instanceId: i-0e78cbf853328b820\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 1c75eedf-8497-46fe-aeb8-dab6a62154cb\n type: Switch.nodes.Compute\n nodetype: t2.medium\n OStype: Ubuntu 16.04\n domain: ec2.us-east-1.amazonaws.com\n script: /tmp/Input-4007028381500/guiscipt.sh\n installation: null\n role: slave\n dockers: mogswitch/ProxyTranscoder\n public_address: 34.207.254.160\n instanceId: i-0a99ea18fcc77ed7a\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"54.144.0.91 ubuntu /tmp/Input-4007028381500/Virginia.pem master\n34.207.254.160 ubuntu /tmp/Input-4007028381500/Virginia.pem slave\n"}]}
\ No newline at end of file
{
"key": "ssh-rsa AAAAB3NzaC1yc2EAAWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNR1ArgFP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv u@host\n",
"name": "id_rsa.pub"
}
<?xml version="1.0" encoding="UTF-8"?>
<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-1.30.xsd">
<facets>
<exclude name="internal_api" />
</facets>
<api-classes>
<include pattern="nl.uva.sne.drip.api.v1.rest.*" />
<include pattern="nl.uva.sne.drip.api.v0.rest.*" />
<include pattern="nl.uva.sne.drip.commons.v1.types.*" />
<include pattern="nl.uva.sne.drip.commons.v0.types.*" />
</api-classes>
<modules>
<swagger disabled="true" />
</modules>
</enunciate>
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.6-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.licensePath>${project.basedir}/../licenseheader.txt</netbeans.hint.licensePath>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>drip</artifactId>
<groupId>nl.uva.sne.drip</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>drip-api</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.5.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.0.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-core</artifactId>
<version>2.5.6.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.2</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<version>2.8.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-planner2provisioner</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<docsDir>${project.build.directory}/docs</docsDir>
<configFile>enunciate.xml</configFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.auth;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.springframework.web.filter.GenericFilterBean;
/**
*
* @author S. Koulouzis
*/
public class AuthFilter extends GenericFilterBean {
@Override
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.auth;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
import org.springframework.stereotype.Component;
/**
*
* @author S. Koulouzis
*/
@Component
public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
throws IOException, ServletException {
// super.commence(request, response, authEx);
response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName() + "");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
PrintWriter writer = response.getWriter();
writer.println("HTTP Status 401 - " + authEx.getMessage());
}
@Override
public void afterPropertiesSet() throws Exception {
setRealmName("DRIP");
super.afterPropertiesSet();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.auth;
import java.io.Serializable;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
/**
*
* @author S. Koulouzis
*/
public class PermissionEvaluatorImp implements PermissionEvaluator {
@Override
public boolean hasPermission(Authentication a, Object o, Object o1) {
if (!a.isAuthenticated()) {
return false;
}
if (!(a.getPrincipal() instanceof User)) {
return false;
} else {
User user = (User) a.getPrincipal();
return true;
}
// return false;
}
@Override
public boolean hasPermission(Authentication a, Serializable srlzbl, String string, Object o) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.conf;
import nl.uva.sne.drip.api.auth.PermissionEvaluatorImp;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
/**
*
* @author alogo
*/
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
DefaultMethodSecurityExpressionHandler expressionHandler
= new DefaultMethodSecurityExpressionHandler();
expressionHandler.setPermissionEvaluator(new PermissionEvaluatorImp());
return expressionHandler;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.conf;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
/**
*
* @author S. Koulouzis
*/
@Configuration
@EnableMongoRepositories(basePackages = "nl.uva.sne.drip.api")
@PropertySources({
@PropertySource(value = "classpath:drip.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:etc/drip.properties", ignoreResourceNotFound = true)
})
@ComponentScan("nl.uva.sne.drip")
public class MongoConfig extends AbstractMongoConfiguration {
@Value("${db.name}")
private String dbName;
@Value("${db.username}")
private String dbUsername;
@Value("${db.password}")
private String dbPass;
// @Autowired
// private MongoDbFactory mongoFactory;
// @Autowired
// private MongoMappingContext mongoMappingContext;
@Override
protected String getDatabaseName() {
return dbName;
}
@Override
public Mongo mongo() throws Exception {
return new MongoClient("127.0.0.1", 27017);
}
@Override
protected String getMappingBasePackage() {
return "nl.uva.sne.drip";
}
}
/*
* Copyright 2016 S. Koulouzis
*
* 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.
*/
package nl.uva.sne.drip.api.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@ComponentScan("nl.uva.sne.drip")
//@PropertySource("classpath:drip.properties")
@PropertySources({
@PropertySource(value = "classpath:drip.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:etc/drip.properties", ignoreResourceNotFound = true)
})
@EnableWebMvc
public class MultipartConfig {
@Bean(name = "multipartResolver")
public CommonsMultipartResolver createMultipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("utf-8");
// resolver.setMaxInMemorySize(0);
//resolver.setMaxUploadSize(0);
//resolver.setMaxUploadSizePerFile(0);
return resolver;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.conf;
import nl.uva.sne.drip.api.auth.MyBasicAuthenticationEntryPoint;
import nl.uva.sne.drip.api.auth.AuthFilter;
import nl.uva.sne.drip.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
/**
*
* @author S. Koulouzis
*/
@Configuration
@EnableWebSecurity
//@EnableGlobalMethodSecurity(jsr250Enabled = true, prePostEnabled = true)
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserService userService;
@Autowired
private MyBasicAuthenticationEntryPoint authenticationEntryPoint;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(passwordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/user/*").hasRole("USER")
.and()
.authorizeRequests()
.antMatchers("/manager/*").hasRole("ADMIN")
.and()
.formLogin()
.and()
.httpBasic()
.authenticationEntryPoint(authenticationEntryPoint);
http.addFilterAfter(new AuthFilter(), BasicAuthenticationFilter.class);
}
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.conf;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
}
/*
* Copyright 2016 S. Koulouzis
*
* 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.
*/
package nl.uva.sne.drip.api.conf;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(MultipartConfig.class);
ctx.register(MongoConfig.class);
ctx.register(SecurityConfig.class);
// ctx.register(MethodSecurityConfig.class);
ctx.setServletContext(servletContext);
Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
dynamic.addMapping("/");
dynamic.setLoadOnStartup(1);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface CloudCredentialsDao extends MongoRepository<CloudCredentials, String> {
@Override
CloudCredentials findOne(String id);
//
// @PreAuthorize(ALLOWED_FOR_ADMINISTRATOR)
// @Override
// void delete(String id);
//
// @PreAuthorize(ALLOWED_FOR_OWNER + " or " + ALLOWED_FOR_ADMINISTRATOR)
// @Override
// List<CloudCredentials> findAll();
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.ClusterCredentials;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ClusterCredentialsDao extends MongoRepository<ClusterCredentials, String> {
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.Plan;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface PlanDao extends MongoRepository<Plan, String> {
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.ProvisionInfo;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ProvisionInfoDao extends MongoRepository<ProvisionInfo, String> {
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.Script;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ScriptDao extends MongoRepository<Script, String> {
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.ToscaRepresentation;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface ToscaDao extends MongoRepository<ToscaRepresentation, String> {
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface UserDao extends MongoRepository<User, String> {
public User findByUsername(String username);
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.commons.v1.types.LoginKey;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface UserKeyDao extends MongoRepository<LoginKey, String> {
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException {
public BadRequestException(String massage) {
super(massage);
}
public BadRequestException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Cloud credentials not found")
public class CloudCredentialsNotFoundException extends RuntimeException {
public CloudCredentialsNotFoundException(String string) {
super(string);
}
public CloudCredentialsNotFoundException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
/**
*
* @author S. Koulouzis
*/
public class ExceptionHandler {
public static RuntimeException generateException(String name, String value) {
if (value == null) {
return new InternalServerErrorExeption();
}
if (value.contains("The maximum number of VPCs has been reached")) {
return new VMLimitException(name + "." + value);
} else {
return new InternalServerErrorExeption();
}
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class InternalServerErrorException extends RuntimeException {
public InternalServerErrorException(String massage) {
super(massage);
}
public InternalServerErrorException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class InternalServerErrorExeption extends RuntimeException {
public InternalServerErrorExeption(String massage) {
super(massage);
}
public InternalServerErrorExeption() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class NotFoundException extends RuntimeException {
public NotFoundException(String string) {
super(string);
}
public NotFoundException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Key can't be null")
public class NullKeyException extends RuntimeException {
public NullKeyException(String string) {
super(string);
}
public NullKeyException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "KeyId can't be null")
public class NullKeyIDException extends RuntimeException {
public NullKeyIDException(String string) {
super(string);
}
public NullKeyIDException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "User already exists")
public class PasswordNullException extends RuntimeException {
public PasswordNullException() {
super();
}
public PasswordNullException(String string) {
super(string);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Plan not found")
public class PlanNotFoundException extends RuntimeException {
public PlanNotFoundException(String string) {
super(string);
}
public PlanNotFoundException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
public class UnauthorizedExeption extends RuntimeException {
public UnauthorizedExeption(String string) {
super(string);
}
public UnauthorizedExeption() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "User already exists")
public class UserExistsException extends RuntimeException {
public UserExistsException() {
super();
}
public UserExistsException(String string) {
super(string);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "User not found")
public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String string) {
super(string);
}
public UserNotFoundException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "User name can't be null")
public class UserNullException extends RuntimeException {
public UserNullException(String massage) {
super(massage);
}
public UserNullException() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "The maximum number of VMs has been reached")
public class VMLimitException extends RuntimeException {
public VMLimitException(String string) {
super(string);
}
public VMLimitException() {
super();
}
}
package nl.uva.sne.drip.api.rpc;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.v1.types.Message;
import nl.uva.sne.drip.commons.v1.types.MessageParameter;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
/**
*
* @author S. Koulouzis
*/
public abstract class DRIPCaller implements AutoCloseable {
private final Connection connection;
private final Channel channel;
private final String replyQueueName;
private final String requestQeueName;
private final ObjectMapper mapper;
public DRIPCaller(String messageBrokerHost, String requestQeueName) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(messageBrokerHost);
factory.setPort(AMQP.PROTOCOL.PORT);
//factory.setUsername("guest");
//factory.setPassword("pass");
connection = factory.newConnection();
channel = connection.createChannel();
// create a single callback queue per client not per requests.
replyQueueName = channel.queueDeclare().getQueue();
this.requestQeueName = requestQeueName;
this.mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
}
/**
* @return the connection
*/
public Connection getConnection() {
return connection;
}
/**
* @return the channel
*/
public Channel getChannel() {
return channel;
}
/**
* @return the replyQueueName
*/
public String getReplyQueueName() {
return replyQueueName;
}
@Override
public void close() throws IOException, TimeoutException {
if (channel != null && channel.isOpen()) {
channel.close();
}
if (connection != null && connection.isOpen()) {
connection.close();
}
}
public Message call(Message r) throws IOException, TimeoutException, InterruptedException, JSONException {
String jsonInString = mapper.writeValueAsString(r);
//Build a correlation ID to distinguish responds
final String corrId = UUID.randomUUID().toString();
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder()
.correlationId(corrId)
.replyTo(getReplyQueueName())
.build();
getChannel().basicPublish("", requestQeueName, props, jsonInString.getBytes("UTF-8"));
final BlockingQueue<String> response = new ArrayBlockingQueue(1);
getChannel().basicConsume(getReplyQueueName(), true, new DefaultConsumer(getChannel()) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
if (properties.getCorrelationId().equals(corrId)) {
response.offer(new String(body, "UTF-8"));
}
}
});
String resp = response.take();
String clean = resp;
if (resp.contains("'null'")) {
clean = resp.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
}
if (clean.contains("\"value\":{\"")) {
return Converter.string2Message(clean);
}
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", clean);
return mapper.readValue(clean, Message.class);
}
private Message unMarshallWithSimpleJson(String strResponse) throws JSONException {
strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
// System.err.println(strResponse);
JSONObject jsonObj = new JSONObject(strResponse);
Message responseMessage = new Message();
responseMessage.setCreationDate((Long) jsonObj.get("creationDate"));
JSONArray jsonParams = (JSONArray) jsonObj.get("parameters");
List<MessageParameter> parameters = new ArrayList<>();
for (int i = 0; i < jsonParams.length(); i++) {
JSONObject jsonParam = (JSONObject) jsonParams.get(i);
MessageParameter parameter = new MessageParameter();
parameter.setName(jsonParam.getString("name"));
parameter.setValue(jsonParam.getString("value"));
parameters.add(parameter);
}
responseMessage.setParameters(parameters);
return responseMessage;//
}
// public Message unmarshall(String strResponse) throws IOException {
//
// mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
// strResponse = strResponse.replaceAll("'null'", "null").replaceAll("\'", "\"").replaceAll(" ", "");
//// return unMarshallWithSimpleJson(strResponse);
// return mapper.readValue(strResponse, Message.class);
// }
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.rpc;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
*
* @author S. Koulouzis
*/
public class DeployerCaller extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "deployer_queue";
public DeployerCaller(String messageBrokerHost) throws IOException, TimeoutException {
super(messageBrokerHost, REQUEST_QUEUE_NAME);
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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.
*/
package nl.uva.sne.drip.api.rpc;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.commons.v1.types.Message;
/**
*
* @author S. Koulouzis.
*/
public class PlannerCaller extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "planner_queue";
public PlannerCaller(String messageBrokerHost) throws IOException, TimeoutException {
super(messageBrokerHost, REQUEST_QUEUE_NAME);
}
public String generateFakeResponse(Message plannerInvokationMessage) throws IOException {
return "{\n"
+ " \"creationDate\": 1487002029722,\n"
+ " \"parameters\": [\n"
+ " {\n"
+ " \"url\": null,\n"
+ " \"encoding\": \"UTF-8\",\n"
+ " \"value\": \"{\\\"name\\\":\\\"2d13d708e3a9441ab8336ce874e08dd1\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+ " \"name\": \"component\",\n"
+ " \"attributes\": null\n"
+ " },\n"
+ " {\n"
+ " \"url\": null,\n"
+ " \"encoding\": \"UTF-8\",\n"
+ " \"value\": \"{\\\"name\\\":\\\"8fcc1788d9ee462c826572c79fdb2a6a\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+ " \"name\": \"component\",\n"
+ " \"attributes\": null\n"
+ " },\n"
+ " {\n"
+ " \"url\": null,\n"
+ " \"encoding\": \"UTF-8\",\n"
+ " \"value\": \"{\\\"name\\\":\\\"5e0add703c8a43938a39301f572e46c0\\\",\\\"size\\\":\\\"Small\\\",\\\"docker\\\":\\\"mogswitch/InputDistributor\\\"}\",\n"
+ " \"name\": \"component\",\n"
+ " \"attributes\": null\n"
+ " }\n"
+ " ]\n"
+ "}";
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.rpc;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
*
* @author S. Koulouzis
*/
public class ProvisionerCaller extends DRIPCaller {
private static final String REQUEST_QUEUE_NAME = "provisioner_queue";
public ProvisionerCaller(String messageBrokerHost) throws IOException, TimeoutException {
super(messageBrokerHost, REQUEST_QUEUE_NAME);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import java.util.List;
import nl.uva.sne.drip.api.dao.CloudCredentialsDao;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class CloudCredentialsService {
@Autowired
private CloudCredentialsDao dao;
public CloudCredentials save(CloudCredentials cloudCredentials) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
cloudCredentials.setOwner(owner);
return dao.save(cloudCredentials);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public CloudCredentials findOne(String id) {
CloudCredentials creds = dao.findOne(id);
return creds;
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public CloudCredentials delete(String id) {
CloudCredentials creds = dao.findOne(id);
dao.delete(creds);
return creds;
}
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
// @PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, 'admin')")
public List<CloudCredentials> findAll() {
return dao.findAll();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.v1.types.Message;
import nl.uva.sne.drip.commons.v1.types.MessageParameter;
import nl.uva.sne.drip.commons.v1.types.Plan;
import nl.uva.sne.drip.commons.v1.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.v1.types.User;
import nl.uva.sne.drip.drip.converter.P2PConverter;
import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class PlannerService {
@Autowired
private ToscaService toscaService;
@Autowired
private PlanDao planDao;
@Value("${message.broker.host}")
private String messageBrokerHost;
public Plan getPlan(String toscaId) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
Message plannerReturnedMessage = (planner.call(plannerInvokationMessage));
// Message plannerReturnedMessage = (planner.generateFakeResponse(plannerInvokationMessage));
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
List<MessageParameter> messageParams = plannerReturnedMessage.getParameters();
StringBuilder jsonArrayString = new StringBuilder();
jsonArrayString.append("[");
String prefix = "";
for (MessageParameter mp : messageParams) {
String value = mp.getValue();
jsonArrayString.append(prefix);
prefix = ",";
String jsonValue = value.replaceAll("\\\"", "\"");
jsonArrayString.append(jsonValue);
}
jsonArrayString.append("]");
SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", "swarm");
Plan topLevel = new Plan();
topLevel.setLevel(0);
topLevel.setToscaID(toscaId);
topLevel.setName("planner_output_all.yml");
topLevel.setKvMap(Converter.ymlString2Map(simplePlan.topLevelContents));
Map<String, String> map = simplePlan.lowerLevelContents;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (String lowLevelNames : map.keySet()) {
Plan lowLevelPlan = new Plan();
lowLevelPlan.setLevel(1);
lowLevelPlan.setToscaID(toscaId);
lowLevelPlan.setName(lowLevelNames);
lowLevelPlan.setKvMap(Converter.ymlString2Map(map.get(lowLevelNames)));
save(lowLevelPlan);
loweLevelPlansIDs.add(lowLevelPlan.getId());
}
topLevel.setLoweLevelPlansIDs(loweLevelPlansIDs);
save(topLevel);
return topLevel;
}
}
private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException {
ToscaRepresentation t2 = toscaService.findOne(toscaId);
if (t2 == null) {
throw new BadRequestException();
}
Map<String, Object> map = t2.getKeyValue();
String json = Converter.map2JsonString(map);
json = json.replaceAll("\\uff0E", "\\.");
byte[] bytes = json.getBytes();
Message invokationMessage = new Message();
List parameters = new ArrayList();
MessageParameter jsonArgument = new MessageParameter();
String charset = "UTF-8";
jsonArgument.setValue(new String(bytes, charset));
jsonArgument.setEncoding(charset);
jsonArgument.setName("input");
parameters.add(jsonArgument);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
}
public String get(String id, String fromat) throws JSONException {
Plan plan = findOne(id);
if (plan == null) {
throw new NotFoundException();
}
Map<String, Object> map = plan.getKeyValue();
Set<String> ids = plan.getLoweLevelPlanIDs();
for (String lowID : ids) {
Map<String, Object> lowLevelMap = findOne(lowID).getKeyValue();
if (lowLevelMap != null) {
map.putAll(lowLevelMap);
}
}
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
public String getToscaID(String id) {
return findOne(id).getToscaID();
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<Plan> findAll() {
List<Plan> all = planDao.findAll();
List<Plan> topLevel = new ArrayList<>();
for (Plan p : all) {
if (p.getLevel() == 0) {
topLevel.add(p);
}
}
return topLevel;
}
public Plan save(Plan plan) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
plan.setOwner(owner);
return planDao.save(plan);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Plan findOne(String lowiID) {
return planDao.findOne(lowiID);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Plan delete(String id) {
Plan plan = planDao.findOne(id);
if (plan == null) {
throw new NotFoundException();
}
planDao.delete(plan);
return plan;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.dao.PlanDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.PlannerCaller;
import nl.uva.sne.drip.commons.v1.types.Message;
import nl.uva.sne.drip.commons.v1.types.MessageParameter;
import nl.uva.sne.drip.commons.v1.types.Plan;
import nl.uva.sne.drip.commons.v1.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class SimplePlannerService {
@Value("${message.broker.host}")
private String messageBrokerHost;
@Autowired
private ToscaService toscaService;
@Autowired
private PlanDao planDao;
public Plan getPlan(String toscaId) throws JSONException, IOException, TimeoutException, InterruptedException {
ToscaRepresentation tosca = toscaService.findOne(toscaId);
Message plannerInvokationMessage = buildSimplePlannerMessage(tosca);
Plan topLevel;
try (PlannerCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerReturnedMessage = (planner.call(plannerInvokationMessage));
List<MessageParameter> planFiles = plannerReturnedMessage.getParameters();
topLevel = new Plan();
Set<String> ids = topLevel.getLoweLevelPlanIDs();
if (ids == null) {
ids = new HashSet<>();
}
Plan lowerLevelPlan = null;
for (MessageParameter p : planFiles) {
//Should have levels in attributes
Map<String, String> attributess = p.getAttributes();
if (attributess != null) {
attributess.get("level");
}
String originalFileName = p.getName();
String name = System.currentTimeMillis() + "_" + originalFileName;
if (originalFileName.equals("planner_output_all.yml")) {
topLevel.setName(name);
topLevel.setLevel(0);
topLevel.setKvMap(Converter.ymlString2Map(p.getValue()));
} else {
lowerLevelPlan = new Plan();
lowerLevelPlan.setName(name);
lowerLevelPlan.setKvMap(Converter.ymlString2Map(p.getValue()));
lowerLevelPlan.setLevel(1);
planDao.save(lowerLevelPlan);
ids.add(lowerLevelPlan.getId());
}
}
topLevel.setLoweLevelPlansIDs(ids);
}
topLevel.setToscaID(toscaId);
planDao.save(topLevel);
return topLevel;
}
private Message buildSimplePlannerMessage(ToscaRepresentation t2) throws JSONException, UnsupportedEncodingException, IOException {
if (t2 == null) {
throw new NotFoundException();
}
Map<String, Object> map = t2.getKeyValue();
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
byte[] bytes = ymlStr.getBytes();
Message invokationMessage = new Message();
List parameters = new ArrayList();
MessageParameter fileArgument = new MessageParameter();
String charset = "UTF-8";
fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset);
fileArgument.setName("input");
parameters.add(fileArgument);
fileArgument = new MessageParameter();
bytes = Files.readAllBytes(Paths.get(System.getProperty("user.home") + File.separator + "Downloads/DRIP/example_a.yml"));
fileArgument.setValue(new String(bytes, charset));
fileArgument.setEncoding(charset);
fileArgument.setName("example");
parameters.add(fileArgument);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
}
public String get(String id, String fromat) throws JSONException {
Plan plan = planDao.findOne(id);
if (plan == null) {
throw new NotFoundException();
}
Map<String, Object> map = plan.getKeyValue();
Set<String> ids = plan.getLoweLevelPlanIDs();
for (String lowID : ids) {
Map<String, Object> lowLevelMap = planDao.findOne(lowID).getKeyValue();
map.putAll(lowLevelMap);
}
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
public PlanDao getDao() {
return planDao;
}
public String getToscaID(String id) {
return planDao.findOne(id).getToscaID();
}
public List<Plan> findAll() {
List<Plan> all = planDao.findAll();
List<Plan> topLevel = new ArrayList<>();
for (Plan p : all) {
if (p.getLevel() == 0) {
topLevel.add(p);
}
}
return topLevel;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.v1.types.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.v1.types.User;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class ToscaService {
@Autowired
private ToscaDao dao;
public String get(String id, String fromat) throws JSONException {
ToscaRepresentation tosca = findOne(id);
if (tosca == null) {
throw new NotFoundException();
}
Map<String, Object> map = tosca.getKeyValue();
if (fromat != null && fromat.equals("yml")) {
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
if (fromat != null && fromat.equals("json")) {
String jsonStr = Converter.map2JsonString(map);
jsonStr = jsonStr.replaceAll("\\uff0E", "\\.");
return jsonStr;
}
String ymlStr = Converter.map2YmlString(map);
ymlStr = ymlStr.replaceAll("\\uff0E", "\\.");
return ymlStr;
}
public String saveFile(MultipartFile file) throws IOException {
String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName;
byte[] bytes = file.getBytes();
String str = new String(bytes, "UTF-8");
str = str.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(str);
ToscaRepresentation t = new ToscaRepresentation();
t.setName(name);
t.setKvMap(map);
save(t);
return t.getId();
}
public String saveYamlString(String yamlString, String name) throws IOException {
if (name == null) {
name = System.currentTimeMillis() + "_" + "tosca.yaml";
}
yamlString = yamlString.replaceAll("\\.", "\uff0E");
Map<String, Object> map = Converter.ymlString2Map(yamlString);
ToscaRepresentation t = new ToscaRepresentation();
t.setName(name);
t.setKvMap(map);
save(t);
return t.getId();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ToscaRepresentation delete(String id) {
ToscaRepresentation tr = dao.findOne(id);
dao.delete(tr);
return tr;
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<ToscaRepresentation> findAll() {
return dao.findAll();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ToscaRepresentation findOne(String id) {
return dao.findOne(id);
}
private ToscaRepresentation save(ToscaRepresentation t) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
t.setOwner(owner);
return dao.save(t);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import java.util.ArrayList;
import java.util.List;
import nl.uva.sne.drip.api.dao.UserKeyDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.v1.types.LoginKey;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class UserKeyService {
@Autowired
UserKeyDao dao;
public List<LoginKey> getAll(LoginKey.Type type) {
List<LoginKey> all = findAll();
if (all != null) {
List<LoginKey> allPublic = new ArrayList<>();
for (LoginKey tr : all) {
if (tr.getType() != null && tr.getType().equals(LoginKey.Type.PUBLIC)) {
allPublic.add(tr);
}
}
return allPublic;
}
return null;
}
public LoginKey get(String id, LoginKey.Type type) {
LoginKey key = findOne(id);
if (key.getType().equals(type)) {
return key;
}
return null;
}
public void delete(String id, LoginKey.Type type) {
LoginKey k = get(id, type);
if (k != null) {
delete(k);
}
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<LoginKey> findAll() {
return dao.findAll();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public LoginKey findOne(String id) {
LoginKey key = dao.findOne(id);
if (key == null) {
throw new NotFoundException();
}
return key;
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public LoginKey delete(LoginKey k) {
k = dao.findOne(k.getId());
dao.delete(k);
return k;
}
public LoginKey save(LoginKey upk) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
upk.setOwner(owner);
return dao.save(upk);
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.ScriptDao;
import nl.uva.sne.drip.commons.v1.types.Script;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.core.context.SecurityContextHolder;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class UserScriptService {
@Autowired
ScriptDao dao;
public Script save(Script script) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
script.setOwner(owner);
return dao.save(script);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Script findOne(String id) {
Script script = dao.findOne(id);
return script;
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Script delete(String id) {
Script script = dao.findOne(id);
dao.delete(script);
return script;
}
// @PreAuthorize(" (hasRole('ROLE_ADMIN')) or (hasRole('ROLE_USER'))")
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
// @PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, 'admin')")
public List<Script> findAll() {
return dao.findAll();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.service;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.dao.UserDao;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class UserService implements UserDetailsService {
public static final String ADMIN = "ADMIN";
public static final String USER = "USER";
@Autowired
private UserDao dao;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
try {
User user = dao.findByUsername(username);
return user;
} catch (Exception ex) {
Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public UserDao getDao() {
return dao;
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.exception.NullKeyException;
import nl.uva.sne.drip.api.exception.NullKeyIDException;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v0.types.Configure;
import nl.uva.sne.drip.commons.v1.types.LoginKey;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
/**
*
* This controller is responsible for handling cloud credentials used by the
* provisoner to request for resources (VMs).
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/account/configure")
@Component
public class CloudConfigurationController0 {
@Autowired
private CloudCredentialsService cloudCredentialsDao;
@RequestMapping(value = "/ec2", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postEC2Conf(@RequestBody Configure configure) {
if (configure.key == null) {
throw new NullKeyException();
}
if (configure.keyid == null) {
throw new NullKeyIDException();
}
CloudCredentials cloudCredentials = new CloudCredentials();
cloudCredentials.setKeyIdAlias(configure.keyid);
cloudCredentials.setKey(configure.key);
List<nl.uva.sne.drip.commons.v1.types.LoginKey> loginKeys = new ArrayList<>();
for (nl.uva.sne.drip.commons.v0.types.LoginKey0 key0 : configure.loginKey) {
nl.uva.sne.drip.commons.v1.types.LoginKey key1 = new nl.uva.sne.drip.commons.v1.types.LoginKey();
key1.setKey(key0.content);
Map<String, String> attributes = new HashMap<>();
attributes.put("domain_name", key0.domain_name);
key1.setAttributes(attributes);
loginKeys.add(key1);
}
cloudCredentials.setLogineKeys(loginKeys);
cloudCredentials.setCloudProviderName("ec2");
cloudCredentials = cloudCredentialsDao.save(cloudCredentials);
return "Success: " + cloudCredentials.getId();
}
@RequestMapping(value = "/geni", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String postGeniConf(@RequestBody Configure configure) {
if (configure.geniKey == null) {
throw new NullKeyException();
}
if (configure.geniKeyAlias == null) {
throw new NullKeyIDException();
}
CloudCredentials cloudCredentials = new CloudCredentials();
cloudCredentials.setKeyIdAlias(configure.geniKeyAlias);
cloudCredentials.setKey(configure.geniKey);
cloudCredentials.setKeyPass(configure.geniKeyPass);
List<nl.uva.sne.drip.commons.v1.types.LoginKey> loginKeys = new ArrayList<>();
for (nl.uva.sne.drip.commons.v0.types.LoginKey0 key0 : configure.loginPubKey) {
nl.uva.sne.drip.commons.v1.types.LoginKey key1 = new nl.uva.sne.drip.commons.v1.types.LoginKey();
key1.setKey(key0.content);
key1.setType(LoginKey.Type.PUBLIC);
loginKeys.add(key1);
}
for (nl.uva.sne.drip.commons.v0.types.LoginKey0 key0 : configure.loginPriKey) {
nl.uva.sne.drip.commons.v1.types.LoginKey key1 = new nl.uva.sne.drip.commons.v1.types.LoginKey();
key1.setKey(key0.content);
key1.setType(LoginKey.Type.PRIVATE);
loginKeys.add(key1);
}
cloudCredentials.setLogineKeys(loginKeys);
cloudCredentials.setCloudProviderName("geni");
cloudCredentialsDao.save(cloudCredentials);
return "Success: " + cloudCredentials.getId();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.DeployClusterService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v0.types.Deploy;
import nl.uva.sne.drip.commons.v0.types.Attribute;
import nl.uva.sne.drip.commons.v0.types.Result;
import nl.uva.sne.drip.commons.v1.types.ClusterCredentials;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for deploying a cluster on provisoned
* resources.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/deploy")
@Component
@PreAuthorize("isAuthenticated()")
public class DeployController0 {
@Autowired
private DeployClusterService deployService;
@RequestMapping(value = "/kubernetes", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result deployKubernetes(@RequestBody Deploy deploy) {
return deploy(deploy, "kubernetes");
}
@RequestMapping(value = "/swarm", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result deploySwarm(@RequestBody Deploy deploy) {
return deploy(deploy, "swarm");
}
private Result deploy(Deploy deploy, String clusterType) {
String provisionID = deploy.action;
ClusterCredentials clusterCred = deployService.deployCluster(provisionID, clusterType);
Result res = new Result();
res.info = "INFO";
res.status = "Success";
List<Attribute> files = new ArrayList<>();
Attribute e = new Attribute();
e.content = clusterCred.getKey();
files.add(e);
res.file = files;
return res;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.commons.v0.types.Result;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ToscaService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.v0.types.Attribute;
import nl.uva.sne.drip.commons.v0.types.Plan;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for planing the type of resources to be
* provisopned based on a TOSCA description.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/plan")
@Component
public class PlannerController0 {
@Autowired
private PlannerService plannerService;
@Autowired
private ToscaService toscaService;
@RequestMapping(value = "/planning", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result plan(@RequestBody Plan plan0) {
try {
String yaml = plan0.file;
yaml = yaml.replaceAll("\\\\n", "\n");
String id = toscaService.saveYamlString(yaml, null);
nl.uva.sne.drip.commons.v1.types.Plan plan1 = plannerService.getPlan(id);
Result r = new Result();
r.info = ("INFO");
r.status = ("Success");
List<Attribute> files = new ArrayList<>();
Attribute e = Converter.plan1toFile(plan1);
files.add(e);
for (String lowiID : plan1.getLoweLevelPlanIDs()) {
nl.uva.sne.drip.commons.v1.types.Plan lowPlan1 = plannerService.findOne(lowiID);
e = Converter.plan1toFile(lowPlan1);
files.add(e);
//Don't save them cause they will be re-uploaded in the provision step
plannerService.delete(lowPlan1.getId());
}
r.file = files;
plannerService.delete(plan1.getId());
return r;
} catch (IOException | JSONException | TimeoutException | InterruptedException ex) {
Logger.getLogger(PlannerController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import java.io.IOException;
import nl.uva.sne.drip.commons.v1.types.ProvisionInfo;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.commons.utils.Converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.PlannerService;
import nl.uva.sne.drip.api.service.ProvisionService;
import nl.uva.sne.drip.api.service.UserKeyService;
import nl.uva.sne.drip.api.service.UserScriptService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v0.types.Execute;
import nl.uva.sne.drip.commons.v0.types.Attribute;
import nl.uva.sne.drip.commons.v0.types.Result;
import nl.uva.sne.drip.commons.v0.types.Upload;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import nl.uva.sne.drip.commons.v1.types.LoginKey;
import nl.uva.sne.drip.commons.v1.types.Script;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for obtaining resources from cloud providers
* based the plan generated by the planner and uploaded by the user
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/provision")
@Component
@PreAuthorize("isAuthenticated()")
public class ProvisionController0 {
@Autowired
private UserScriptService userScriptService;
@Autowired
private UserKeyService userKeysService;
@Autowired
private CloudCredentialsService cloudCredentialsService;
@Autowired
private ProvisionService provisionService;
@Autowired
private PlannerService planService;
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String provision(@RequestBody Upload upload) {
ProvisionInfo provInfo = new ProvisionInfo();
CloudCredentials cloudCred = cloudCredentialsService.findAll().get(0);
String cloudCredID = cloudCred.getId();
provInfo.setCloudcloudCredentialsID(cloudCredID);
List<nl.uva.sne.drip.commons.v0.types.Attribute> plans = upload.file;
nl.uva.sne.drip.commons.v1.types.Plan topLevelPlan = null;
Set<String> loweLevelPlansIDs = new HashSet<>();
for (nl.uva.sne.drip.commons.v0.types.Attribute p : plans) {
nl.uva.sne.drip.commons.v1.types.Plan plan1 = Converter.File2Plan1(p);
if (plan1.getLevel() == 0) {
topLevelPlan = plan1;
} else {
plan1 = planService.save(plan1);
loweLevelPlansIDs.add(plan1.getId());
}
}
topLevelPlan.setLoweLevelPlansIDs(loweLevelPlansIDs);
topLevelPlan = planService.save(topLevelPlan);
String planID = topLevelPlan.getId();
provInfo.setPlanID(planID);
List<LoginKey> allKeys = userKeysService.findAll();
if (allKeys != null && !allKeys.isEmpty()) {
String userKeyID = allKeys.get(0).getId();
provInfo.setUserKeyID(userKeyID);
}
List<Script> allScripts = userScriptService.findAll();
if (allScripts != null && !allScripts.isEmpty()) {
String scriptID = allScripts.get(0).getId();
provInfo.setScriptID(scriptID);
}
provInfo = provisionService.save(provInfo);
return "Success: Infrastructure files are uploaded! Action number: "
+ provInfo.getId();
}
@RequestMapping(value = "/execute", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
Result execute(@RequestBody Execute exc) {
try {
ProvisionInfo req = provisionService.findOne(exc.action);
req = provisionService.provisionResources(req);
Map<String, Object> map = req.getKeyValue();
String yaml = Converter.map2YmlString(map);
yaml = yaml.replaceAll("\n", "\\\\n");
Result res = new Result();
List<Attribute> files = new ArrayList<>();
Attribute e = new Attribute();
e.content = yaml;
e.level = "0";
e.name = "provisioned_" + exc.action;
files.add(e);
res.info = "INFO";
res.status = "Success";
res.file = files;
return res;
} catch (IOException | TimeoutException | JSONException | InterruptedException ex) {
Logger.getLogger(ProvisionController0.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.exception.PasswordNullException;
import nl.uva.sne.drip.api.exception.UserExistsException;
import nl.uva.sne.drip.api.exception.UserNullException;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v0.types.Register;
import org.springframework.http.MediaType;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for handling user accounts
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/manager/v0.0/switch/account")
@Component
public class UserController0 {
@Autowired
private UserService service;
@RequestMapping(value = "/register", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.ADMIN})
public @ResponseBody
String register(@RequestBody Register register) {
if (register.user == null) {
throw new UserNullException();
}
if (register.pwd == null) {
throw new PasswordNullException();
}
UserDetails registeredUser = service.loadUserByUsername(register.user);
if (registeredUser != null) {
throw new UserExistsException("Username " + register.user + " is used");
}
User user = new User();
user.setUsername(register.user);
user.setPassword(new BCryptPasswordEncoder().encode(register.pwd));
service.getDao().save(user);
return "Success: " + user.getId();
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.service.ProvisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserKeyService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v0.types.ConfUserKey;
import nl.uva.sne.drip.commons.v1.types.LoginKey;
import nl.uva.sne.drip.commons.v1.types.ProvisionInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for handling user public keys. These keys can
* be used by the provisoner to allow the user to login to the VMs from the
* machine the keys correspond to.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/provision")
@Component
public class UserPublicKeysController0 {
@Autowired
private UserKeyService service;
@Autowired
private ProvisionService provisionService;
@RequestMapping(value = "/confuserkey", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserPublicKeys(@RequestBody ConfUserKey confUserKey) {
LoginKey upk = new LoginKey();
upk.setKey(confUserKey.file.get(0).content);
upk.setName(confUserKey.file.get(0).name);
upk.setType(LoginKey.Type.PUBLIC);
upk = service.save(upk);
ProvisionInfo provPlan = provisionService.findOne(confUserKey.action);
provPlan.setUserKeyID(upk.getId());
provisionService.save(provPlan);
return "Success: " + upk.getId();
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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.
*/
package nl.uva.sne.drip.api.v0.rest;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.api.service.ProvisionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.service.UserScriptService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v0.types.ConfScript;
import nl.uva.sne.drip.commons.v1.types.ProvisionInfo;
import nl.uva.sne.drip.commons.v1.types.Script;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* This controller is responsible for handling user scripts. These user can be
* used by the provisoner to run on the created VMs.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v0.0/switch/provision")
@Component
public class UserScriptController0 {
@Autowired
private UserScriptService scriptService;
@Autowired
private ProvisionService provisionService;
@RequestMapping(value = "/confscript", method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String uploadUserScript(@RequestBody ConfScript confScript) {
Script script = new Script();
script.setContents(confScript.script);
script = scriptService.save(script);
ProvisionInfo provPlan = provisionService.findOne(confScript.action);
provPlan.setScriptID(script.getId());
provisionService.save(provPlan);
return "Success: script for GUI is uploaded: " + script.getId();
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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.
*/
package nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.commons.v1.types.CloudCredentials;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.NullKeyException;
import nl.uva.sne.drip.api.exception.NullKeyIDException;
import nl.uva.sne.drip.api.service.CloudCredentialsService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.commons.v1.types.LoginKey;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
/**
*
* This controller is responsible for handling CloudCredentials.
* CloudCredentials are a represntation of the credentials that are used by the
* provisoner to request for resources (VMs)
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v1.0/credentials/cloud")
@Component
public class CloudCredentialsController {
@Autowired
private CloudCredentialsService cloudCredentialsService;
/**
* Post the cloud credentials.
*
* @param cloudCredentials
* @return the CloudCredentials id
*/
@RequestMapping(method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
@StatusCodes({
@ResponseCode(code = 400, condition = "Key or KeyIdAlias can't be empty")
})
public @ResponseBody
String postConf(@RequestBody CloudCredentials cloudCredentials) {
if (cloudCredentials.getKey() == null) {
throw new NullKeyException();
}
if (cloudCredentials.getKeyIdAlias() == null) {
throw new NullKeyIDException();
}
// User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
cloudCredentials = cloudCredentialsService.save(cloudCredentials);
return cloudCredentials.getId();
}
/**
* Upload the login keys for a cloud provider. The cloud credentials have to
* be created
*
* @param file
* @param id
* @return the CloudCredentials id
*/
@RequestMapping(value = "/upload/{id}", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String addLogineKey(@RequestParam("file") MultipartFile file, @PathVariable("id") String id) {
try {
CloudCredentials cloudCredentials = cloudCredentialsService.findOne(id);
if (cloudCredentials == null) {
throw new NotFoundException();
}
if (file.isEmpty()) {
throw new BadRequestException("Must uplaod a file");
}
String originalFileName = file.getOriginalFilename();
byte[] bytes = file.getBytes();
List<LoginKey> logInKeys = cloudCredentials.getLoginKeys();
if (logInKeys == null) {
logInKeys = new ArrayList<>();
}
LoginKey key = new LoginKey();
key.setKey(new String(bytes, "UTF-8"));
if (cloudCredentials.getCloudProviderName().toLowerCase().equals("ec2")) {
Map<String, String> attributes = new HashMap<>();
attributes.put("domain_name", FilenameUtils.removeExtension(originalFileName));
key.setAttributes(attributes);
}
logInKeys.add(key);
cloudCredentials.setLogineKeys(logInKeys);
// User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
cloudCredentials = cloudCredentialsService.save(cloudCredentials);
return cloudCredentials.getId();
} catch (IOException ex) {
Logger.getLogger(CloudCredentialsController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* Get the cloud credentials
*
* @param id the id of the cloud credentials
* @return the cloud credentials
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
CloudCredentials get(@PathVariable("id") String id) {
// User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
CloudCredentials cc = cloudCredentialsService.findOne(id);
if (cc == null) {
throw new NotFoundException();
}
return cc;
}
/**
* Delete the cloud credentials
*
* @param id the id of the cloud credentials
* @return the id of the cloud credentials
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
cloudCredentialsService.delete(id);
return "Deleted :" + id;
}
/**
* Gets all the IDs of the stored cloud credentials
*
* @return a list of stored IDs
*/
@RequestMapping(value = "/ids", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
List<String> getIds() {
List<CloudCredentials> all = cloudCredentialsService.findAll();
List<String> ids = new ArrayList<>();
for (CloudCredentials tr : all) {
ids.add(tr.getId());
}
return ids;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment