You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

393 lines
12 KiB

  1. {
  2. "AWSTemplateFormatVersion": "2010-09-09",
  3. "Parameters": {
  4. "paramImageID": {
  5. "Type": "AWS::EC2::Image::Id",
  6. "Default": "ami-f573e19a",
  7. "Description": "Amazon Image ID (Amazon Linux), Frankfurt ami-f573e19a, N. Virginia ami-4dd18837"
  8. },
  9. "paramInstanceType": {
  10. "Type": "String",
  11. "Default": "t2.nano",
  12. "AllowedValues": [
  13. "t2.nano",
  14. "t2.micro",
  15. "m1.small"
  16. ],
  17. "Description": "Enter t2.micro, m1.small, or m1.large. Default is t2.micro."
  18. },
  19. "paramKeyPair": {
  20. "Type": "AWS::EC2::KeyPair::KeyName",
  21. "Description": "Amazon EC2 Key Pair"
  22. },
  23. "paramIamInstanceRole": {
  24. "Type": "String",
  25. "Default": "ec2-s3-vertsys-access-role",
  26. "Description": "IAM Instance Role"
  27. },
  28. "paramVPC": {
  29. "Type": "AWS::EC2::VPC::Id",
  30. "Description": "VPC"
  31. },
  32. "paramSubnetIDs": {
  33. "Type": "List<AWS::EC2::Subnet::Id>",
  34. "Description": "Subnet IDs"
  35. },
  36. "paramAvailabilityZones": {
  37. "Type": "List<AWS::EC2::AvailabilityZone::Name>",
  38. "Description": "AvailabilityZones"
  39. }
  40. },
  41. "Resources": {
  42. "lcVertSysAutoScaleConfigv11": {
  43. "Type": "AWS::AutoScaling::LaunchConfiguration",
  44. "Properties": {
  45. "AssociatePublicIpAddress": true,
  46. "ImageId": {
  47. "Ref": "paramImageID"
  48. },
  49. "InstanceType": {
  50. "Ref": "paramInstanceType"
  51. },
  52. "KeyName": {
  53. "Ref": "paramKeyPair"
  54. },
  55. "IamInstanceProfile": {
  56. "Ref": "paramIamInstanceRole"
  57. },
  58. "SecurityGroups": [
  59. {
  60. "Ref": "sgCloudCompDemoSecurityGroup"
  61. }
  62. ],
  63. "UserData": {
  64. "Fn::Base64": {
  65. "Fn::Join": [
  66. "",
  67. [
  68. "#!/bin/bash\n",
  69. "\n",
  70. "# this script will be run during the boot process by each VertSys instance created\n",
  71. "# in AWS currently this is a plain bash script that requires a RedHat based image\n",
  72. "# (AMI) could be ported to cloud-init for better compatibility with other Linux\n",
  73. "# distros\n",
  74. "#\n",
  75. "# see https://docs.aws.amazon.com/de_de/AWSEC2/latest/UserGuide/user-data.html\n",
  76. "\n",
  77. "# Config\n",
  78. "SCRIPT_ROOT_PATH=\"/tmp/init-script\"\n",
  79. "VERTSYS_PATH=\"$SCRIPT_ROOT_PATH/verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/\"\n",
  80. "#JARS = \"TCPServer.jar TCPServerMulti.jar UDPServer.jar UDPServerMulti.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPPerfServer.jar\"\n",
  81. "JARS=\"TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPTimeCounterRESTServer.jar\"\n",
  82. "REPO=\"https://gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git\"\n",
  83. "\n",
  84. "# Create path to run the script\n",
  85. "mkdir $SCRIPT_ROOT_PATH\n",
  86. "cd $SCRIPT_ROOT_PATH\n",
  87. "\n",
  88. "# fetch user-data (should be the content of this script itself ;)) to be able check it later and run it again\n",
  89. "wget http://169.254.169.254/latest/user-data\n",
  90. "chmod +x user-data\n",
  91. "wget http://169.254.169.254/latest/meta-data/placement/availability-zone\n",
  92. "\n",
  93. "# setting console prompt to include location (availability zone and region in AWS)\n",
  94. "echo \"PS1='[\\u@\\h@\\e[32m`cat /tmp/init-script/availability-zone`\\e[32m \\W]$ '\" >>/root/.bashrc\n",
  95. "echo \"PS1='[\\u@\\h@\\e[32m`cat /tmp/init-script/availability-zone`\\e[39m \\W]$ '\" >>/home/ec2-user/.bashrc\n",
  96. "\n",
  97. "# wait for internet connection, should not be necessary, but just in case ;)\n",
  98. "while ! ping -c 1 -W 1 8.8.8.8; do\n",
  99. " echo \"Waiting for 8.8.8.8 - network interface might be down...\"\n",
  100. " sleep 1\n",
  101. "done\n",
  102. "\n",
  103. "# installation of required packages\n",
  104. "echo \"Installing packages...\"\n",
  105. "sudo yum update -y\n",
  106. "sudo yum install -y java-1.8.0-openjdk-devel git\n",
  107. "#rm -rf verteilte-systeme-bsc-ai-examples\n",
  108. "if [ ! -d $VERTSYS_PATH ]; then\n",
  109. " echo \"Cloning repo...\"\n",
  110. " git clone $REPO\n",
  111. "fi\n",
  112. "\n",
  113. "# killall running screens, .e.g to cleanup if script is run again after boot\n",
  114. "killall screen\n",
  115. "# start all jars\n",
  116. "echo \"Starting JARS: ${JARS}...\"\n",
  117. "for JAR in $JARS; do\n",
  118. " echo \"Starting ${JAR}...\"\n",
  119. " sudo screen -dmS $JAR -L java -jar $VERTSYS_PATH/$JAR\n",
  120. "done\n",
  121. "\n",
  122. "# wait a second, to allow java services to start\n",
  123. "sleep 1\n",
  124. "\n",
  125. "# output status of ports 36000-36199 and all running processes\n",
  126. "echo \"Status:\"\n",
  127. "sudo netstat -taupen | grep 36[0,1][0-9][0-9]\n",
  128. "sudo ps aux | grep java\n",
  129. "\n",
  130. "# Example for path and contents:\n",
  131. "#\n",
  132. "# ./verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/\n",
  133. "#\n",
  134. "#build-server-jars.xml TCPServerMulti.jar\n",
  135. "#RMIEchoServer.jar UDPServer.jar\n",
  136. "#RMIMandelbrotCalculationsServer.jar UDPServerMulti.jar\n",
  137. "#TCPPerfServer.jar UDPTimeCounterServer.jar\n",
  138. "#TCPServer.jar\n"
  139. ]
  140. ]
  141. }
  142. }
  143. }
  144. },
  145. "sgCloudCompDemoSecurityGroup": {
  146. "Type": "AWS::EC2::SecurityGroup",
  147. "Properties": {
  148. "GroupDescription": "CloudComp Counter Demo",
  149. "VpcId": {
  150. "Ref": "paramVPC"
  151. }
  152. }
  153. },
  154. "ingress1": {
  155. "Type": "AWS::EC2::SecurityGroupIngress",
  156. "Properties": {
  157. "GroupId": {
  158. "Ref": "sgCloudCompDemoSecurityGroup"
  159. },
  160. "IpProtocol": "tcp",
  161. "FromPort": "36037",
  162. "ToPort": "36137",
  163. "CidrIp": "0.0.0.0/0"
  164. }
  165. },
  166. "ingress2": {
  167. "Type": "AWS::EC2::SecurityGroupIngress",
  168. "Properties": {
  169. "GroupId": {
  170. "Ref": "sgCloudCompDemoSecurityGroup"
  171. },
  172. "IpProtocol": "tcp",
  173. "FromPort": "22",
  174. "ToPort": "22",
  175. "CidrIp": "0.0.0.0/0"
  176. }
  177. },
  178. "ingress3": {
  179. "Type": "AWS::EC2::SecurityGroupIngress",
  180. "Properties": {
  181. "GroupId": {
  182. "Ref": "sgCloudCompDemoSecurityGroup"
  183. },
  184. "IpProtocol": "udp",
  185. "FromPort": "36037",
  186. "ToPort": "36137",
  187. "CidrIp": "0.0.0.0/0"
  188. }
  189. },
  190. "egress1": {
  191. "Type": "AWS::EC2::SecurityGroupEgress",
  192. "Properties": {
  193. "GroupId": {
  194. "Ref": "sgCloudCompDemoSecurityGroup"
  195. },
  196. "IpProtocol": "-1",
  197. "CidrIp": "0.0.0.0/0"
  198. }
  199. },
  200. "asgCloudCompAutoScaleGroup": {
  201. "Type": "AWS::AutoScaling::AutoScalingGroup",
  202. "Properties": {
  203. "AvailabilityZones": {
  204. "Ref": "paramAvailabilityZones"
  205. },
  206. "TargetGroupARNs": [
  207. {
  208. "Ref": "elbCloudCompTargetGroup"
  209. }
  210. ],
  211. "Cooldown": "30",
  212. "DesiredCapacity": "1",
  213. "HealthCheckGracePeriod": "60",
  214. "HealthCheckType": "EC2",
  215. "MaxSize": "3",
  216. "MinSize": "1",
  217. "VPCZoneIdentifier": {
  218. "Ref": "paramSubnetIDs"
  219. },
  220. "LaunchConfigurationName": {
  221. "Ref": "lcVertSysAutoScaleConfigv11"
  222. },
  223. "MetricsCollection": [
  224. {
  225. "Granularity": "1Minute",
  226. "Metrics": [
  227. "GroupPendingInstances",
  228. "GroupMinSize",
  229. "GroupDesiredCapacity",
  230. "GroupTerminatingInstances",
  231. "GroupInServiceInstances",
  232. "GroupStandbyInstances",
  233. "GroupMaxSize",
  234. "GroupTotalInstances"
  235. ]
  236. }
  237. ],
  238. "TerminationPolicies": [
  239. "Default"
  240. ]
  241. }
  242. },
  243. "sgCloudCompScalePolicy": {
  244. "Type": "AWS::AutoScaling::ScalingPolicy",
  245. "DependsOn": "elbCloudCompListener",
  246. "Properties": {
  247. "PolicyType": "TargetTrackingScaling",
  248. "EstimatedInstanceWarmup": 60,
  249. "TargetTrackingConfiguration": {
  250. "DisableScaleIn": false,
  251. "TargetValue": 5,
  252. "PredefinedMetricSpecification": {
  253. "PredefinedMetricType": "ALBRequestCountPerTarget",
  254. "ResourceLabel": {
  255. "Fn::Join": [
  256. "/",
  257. [
  258. "app/elbCloudCompLoadBalancer",
  259. {
  260. "Fn::Select": [
  261. "3",
  262. {
  263. "Fn::Split": [
  264. "/",
  265. {
  266. "Ref": "elbCloudCompLoadBalancer"
  267. }
  268. ]
  269. }
  270. ]
  271. },
  272. "targetgroup/elbCloudCompTargetGroup",
  273. {
  274. "Fn::Select": [
  275. "2",
  276. {
  277. "Fn::Split": [
  278. "/",
  279. {
  280. "Ref": "elbCloudCompTargetGroup"
  281. }
  282. ]
  283. }
  284. ]
  285. }
  286. ]
  287. ]
  288. }
  289. }
  290. },
  291. "AutoScalingGroupName": {
  292. "Ref": "asgCloudCompAutoScaleGroup"
  293. }
  294. }
  295. },
  296. "elbCloudCompLoadBalancer": {
  297. "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
  298. "Properties": {
  299. "Name": "elbCloudCompLoadBalancer",
  300. "IpAddressType": "ipv4",
  301. "Type": "application",
  302. "Scheme": "internet-facing",
  303. "SecurityGroups": [
  304. {
  305. "Ref": "sgCloudCompDemoSecurityGroup"
  306. }
  307. ],
  308. "Subnets": {
  309. "Ref": "paramSubnetIDs"
  310. }
  311. }
  312. },
  313. "elbCloudCompTargetGroup": {
  314. "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
  315. "Properties": {
  316. "Port": 36042,
  317. "HealthCheckIntervalSeconds": 30,
  318. "HealthCheckTimeoutSeconds": 5,
  319. "HealthyThresholdCount": 2,
  320. "UnhealthyThresholdCount": 2,
  321. "HealthCheckPath": "/counter",
  322. "HealthCheckProtocol": "HTTP",
  323. "TargetGroupAttributes": [
  324. {
  325. "Key": "deregistration_delay.timeout_seconds",
  326. "Value": "20"
  327. }
  328. ],
  329. "Protocol": "HTTP",
  330. "TargetType": "instance",
  331. "Matcher": {
  332. "HttpCode": "200"
  333. },
  334. "Name": "elbCloudCompTargetGroup",
  335. "VpcId": {
  336. "Ref": "paramVPC"
  337. }
  338. }
  339. },
  340. "elbCloudCompListener": {
  341. "Type": "AWS::ElasticLoadBalancingV2::Listener",
  342. "Properties": {
  343. "LoadBalancerArn": {
  344. "Ref": "elbCloudCompLoadBalancer"
  345. },
  346. "Protocol": "HTTP",
  347. "Port": 36042,
  348. "DefaultActions": [
  349. {
  350. "Type": "forward",
  351. "TargetGroupArn": {
  352. "Ref": "elbCloudCompTargetGroup"
  353. }
  354. }
  355. ]
  356. }
  357. }
  358. },
  359. "Outputs": {
  360. "LoadBalancer": {
  361. "Description": "Load Balancer",
  362. "Value": {
  363. "Ref": "elbCloudCompLoadBalancer"
  364. }
  365. },
  366. "LoadBalancerDns": {
  367. "Description": "Load Balancer DNS",
  368. "Value": {
  369. "Fn::GetAtt": [
  370. "elbCloudCompLoadBalancer",
  371. "DNSName"
  372. ]
  373. }
  374. },
  375. "LoadBalancerURL": {
  376. "Description": "Load Balancer URL",
  377. "Value": {
  378. "Fn::Join": [
  379. ":",
  380. [
  381. {
  382. "Fn::GetAtt": [
  383. "elbCloudCompLoadBalancer",
  384. "DNSName"
  385. ]
  386. },
  387. "36042/counter"
  388. ]
  389. ]
  390. }
  391. }
  392. },
  393. "Description": "CloudComp Counter Demo"
  394. }