9352f703c693dc26a5ba35239f7a9b809feba4c6
[alto.git] / alto-manager / src / main / java / org / opendaylight / alto / manager / AltoDelete.java
1 package org.opendaylight.alto.manager;
2
3 import java.io.IOException;
4
5 import org.apache.felix.gogo.commands.Argument;
6 import org.apache.felix.gogo.commands.Command;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 @Command(scope = "alto", name = "delete", description = "Destroy a map by resourceId")
11 public class AltoDelete extends AltoManager {
12   private static final Logger log = LoggerFactory.getLogger(AltoDelete.class);
13
14   @Argument(index = 0, name = "resource-type", description = "Resource Type", required = true, multiValued = false)
15   String resourceType = null;
16   
17   @Argument(index = 1, name = "resource-id", description = "Resource Id", required = true, multiValued = false)
18   String resourceId = null;
19   
20   public AltoDelete() {
21     super();
22   }
23   
24   @Override
25   protected Object doExecute() throws Exception {
26     if (isDefaultNetworkMap(resourceId)) {
27       log.info("Cannot destroy default network map. Aborting");
28     }
29     
30     if (networkMapType().equals(resourceType)) {
31       deleteNetworkMap();
32     } else if (costMapType().equals(resourceType)) {
33       deleteCostMap();
34     } else if (endpointPropertyMapType().equals(resourceType)) {
35       deleteEndpointPropertyMap();
36     } else {
37       log.warn("Not supported resource type " + resourceType + ". Aborting...");
38     }
39     return null;
40   }
41   
42   private boolean deleteEndpointPropertyMap() throws IOException {
43     log.info("Deleting endpoint property map " + this.resourceId);
44     return httpDelete(AltoManagerConstants.RESOURCES_URL + AltoManagerConstants.ENDPOINT_PROPERTY_MAP_NODE);
45   }
46   
47   private boolean deleteCostMap() throws IOException {
48     log.info("Deleting endpoint property map " + this.resourceId);
49     return httpDelete(AltoManagerConstants.COST_MAP_URL + resourceId);
50   }
51   
52   private boolean deleteNetworkMap() throws IOException {
53     log.info("Deleting endpoint property map " + this.resourceId);
54     return httpDelete(AltoManagerConstants.NETWORK_MAP_URL + resourceId);
55   }
56 }