| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.servermanager; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | import java.util.concurrent.atomic.AtomicInteger; |
| 23 | |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import com.google.common.collect.ImmutableMap; |
| 27 | import com.google.common.collect.Maps; |
| 28 | |
| 29 | /** |
| 30 | * This would be replaced with the real connection to the service that can |
| 31 | * create/list/reboot/get/destroy things |
| 32 | * |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | @Singleton |
| 36 | public class ServerManager { |
| 37 | |
| 38 | private final static Map<Integer, Server> servers = Maps.newHashMap(); |
| 39 | private final static Map<Integer, Image> images = ImmutableMap.of(1, new Image(1, "ubuntu")); |
| 40 | private final static Map<Integer, Hardware> hardware = ImmutableMap.of(1, new Hardware(1, "small", 1, 512, 10)); |
| 41 | |
| 42 | private final static AtomicInteger nodeIds = new AtomicInteger(0); |
| 43 | |
| 44 | /** |
| 45 | * simulate creating a server, as this is really going to happen with the api underneath |
| 46 | * |
| 47 | * @param name |
| 48 | * @param name |
| 49 | * @param imageId |
| 50 | * @param hardwareId |
| 51 | * @return new server |
| 52 | */ |
| 53 | public Server createServerInDC(String datacenter, String name, int imageId, int hardwareId) { |
| 54 | Server server = new Server(); |
| 55 | server.id = nodeIds.getAndIncrement(); |
| 56 | server.name = name; |
| 57 | server.datacenter = datacenter; |
| 58 | server.imageId = imageId; |
| 59 | server.hardwareId = hardwareId; |
| 60 | server.publicAddress = "7.1.1." + server.id; |
| 61 | server.privateAddress = "10.1.1." + server.id; |
| 62 | server.loginUser = "root"; |
| 63 | server.password = "password"; |
| 64 | servers.put(server.id, server); |
| 65 | return server; |
| 66 | } |
| 67 | |
| 68 | public Server getServer(int serverId) { |
| 69 | return servers.get(serverId); |
| 70 | } |
| 71 | |
| 72 | public Iterable<Server> listServers() { |
| 73 | return servers.values(); |
| 74 | } |
| 75 | |
| 76 | public Image getImage(int imageId) { |
| 77 | return images.get(imageId); |
| 78 | } |
| 79 | |
| 80 | public Iterable<Image> listImages() { |
| 81 | return images.values(); |
| 82 | } |
| 83 | |
| 84 | public Hardware getHardware(int hardwareId) { |
| 85 | return hardware.get(hardwareId); |
| 86 | } |
| 87 | |
| 88 | public Iterable<org.jclouds.servermanager.Hardware> listHardware() { |
| 89 | return hardware.values(); |
| 90 | } |
| 91 | |
| 92 | public void destroyServer(int serverId) { |
| 93 | servers.remove(serverId); |
| 94 | } |
| 95 | |
| 96 | public void rebootServer(int serverId) { |
| 97 | } |
| 98 | |
| 99 | public void stopServer(int serverId) { |
| 100 | } |
| 101 | |
| 102 | public void startServer(int serverId) { |
| 103 | } |
| 104 | } |