Add service reference binding to config registry.
[controller.git] / opendaylight / config / config-util / src / main / java / org / opendaylight / controller / config / util / jolokia / ConfigRegistryJolokiaClient.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.util.jolokia;
9
10 import java.util.List;
11 import java.util.Map;
12 import java.util.Set;
13
14 import javax.management.InstanceNotFoundException;
15 import javax.management.ObjectName;
16
17 import org.jolokia.client.request.J4pExecRequest;
18 import org.jolokia.client.request.J4pReadRequest;
19 import org.jolokia.client.request.J4pResponse;
20 import org.json.simple.JSONArray;
21 import org.json.simple.JSONObject;
22 import org.opendaylight.controller.config.api.ConflictingVersionException;
23 import org.opendaylight.controller.config.api.ValidationException;
24 import org.opendaylight.controller.config.api.jmx.CommitStatus;
25 import org.opendaylight.controller.config.api.jmx.ConfigRegistryMXBean;
26 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
27 import org.opendaylight.controller.config.util.ConfigRegistryClient;
28
29 @Deprecated
30 public class ConfigRegistryJolokiaClient extends ListableJolokiaClient
31         implements ConfigRegistryClient {
32
33     public ConfigRegistryJolokiaClient(String url) {
34         super(url, ConfigRegistryMXBean.OBJECT_NAME);
35     }
36
37     @Override
38     public ConfigTransactionJolokiaClient createTransaction() {
39         // create transaction
40         J4pExecRequest execReq = new J4pExecRequest(objectName, "beginConfig");
41         J4pResponse<J4pExecRequest> resp = execute(execReq);
42         ObjectName transactionControllerON = extractObjectName(resp);
43         return getConfigTransactionClient(transactionControllerON);
44     }
45
46     @Override
47     public ConfigTransactionJolokiaClient getConfigTransactionClient(
48             String transactionName) {
49         ObjectName objectName = ObjectNameUtil
50                 .createTransactionControllerON(transactionName);
51         return getConfigTransactionClient(objectName);
52     }
53
54     @Override
55     public ConfigTransactionJolokiaClient getConfigTransactionClient(
56             ObjectName objectName) {
57         return new ConfigTransactionJolokiaClient(url, objectName, this);
58     }
59
60     @Override
61     public CommitStatus commitConfig(ObjectName transactionControllerON)
62             throws ConflictingVersionException, ValidationException {
63         J4pExecRequest execReq = new J4pExecRequest(objectName, "commitConfig",
64                 transactionControllerON);
65         JSONObject jsonObject;
66         jsonObject = execute(execReq).getValue();
67         JSONArray newInstancesArray = (JSONArray) jsonObject
68                 .get("newInstances");
69         List<ObjectName> newInstances = jsonArrayToObjectNames(newInstancesArray);
70         JSONArray reusedInstancesArray = (JSONArray) jsonObject
71                 .get("reusedInstances");
72         List<ObjectName> reusedInstances = jsonArrayToObjectNames(reusedInstancesArray);
73         JSONArray recreatedInstancesArray = (JSONArray) jsonObject
74                 .get("recreatedInstances");
75         List<ObjectName> recreatedInstances = jsonArrayToObjectNames(recreatedInstancesArray);
76         return new CommitStatus(newInstances, reusedInstances,
77                 recreatedInstances);
78     }
79
80     public Object getAttribute(ObjectName configBeanTransactionON, String key) {
81         J4pReadRequest req = new J4pReadRequest(configBeanTransactionON, key);
82         return execute(req).getValue();
83     }
84
85     public ObjectName getAttributeON(ObjectName configBeanTransactionON,
86             String key) {
87         JSONObject jsonAttrib = (JSONObject) getAttribute(
88                 configBeanTransactionON, key);
89         return extractObjectName(jsonAttrib);
90     }
91
92     // proxy around ConfigTransactionManagerMXBean
93
94     @Override
95     public ObjectName beginConfig() {
96         ConfigTransactionJolokiaClient result = createTransaction();
97         return result.getTransactionON();
98     }
99
100     @Override
101     public List<ObjectName> getOpenConfigs() {
102         J4pReadRequest req = new J4pReadRequest(objectName, "OpenConfigs");
103         JSONArray jsonArray = execute(req).getValue();
104         return jsonArrayToObjectNames(jsonArray);
105     }
106
107     @Override
108     public long getVersion() {
109         J4pReadRequest req = new J4pReadRequest(objectName, "Version");
110         return (Long) execute(req).getValue();
111     }
112
113     @Override
114     public boolean isHealthy() {
115         J4pReadRequest req = new J4pReadRequest(objectName, "Healthy");
116         return (Boolean) execute(req).getValue();
117     }
118
119     @Override
120     public Set<ObjectName> lookupRuntimeBeans() {
121         return lookupSomething("lookupRuntimeBeans()", new Object[0]);
122     }
123
124     @Override
125     public Set<ObjectName> lookupRuntimeBeans(String moduleName,
126             String instanceName) {
127         return lookupSomething(
128                 "lookupRuntimeBeans(java.lang.String,java.lang.String)",
129                 new Object[] { moduleName, instanceName });
130     }
131
132     @Override
133     public Object invokeMethod(ObjectName on, String name, Object[] params,
134             String[] signature) {
135         throw new UnsupportedOperationException();
136     }
137
138     @Override
139     public Object getAttributeCurrentValue(ObjectName on, String attributeName) {
140         throw new UnsupportedOperationException();
141     }
142
143     // TODO: implement or deprecate
144     @Override
145     public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
146         throw new UnsupportedOperationException();
147     }
148
149     @Override
150     public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceName, String refName) {
151         throw new UnsupportedOperationException();
152     }
153
154     @Override
155     public Map<String, Map<String, ObjectName>> getServiceMapping() {
156         throw new UnsupportedOperationException();
157     }
158
159     @Override
160     public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceName) {
161         throw new UnsupportedOperationException();
162     }
163
164     @Override
165     public Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
166         throw new UnsupportedOperationException();
167     }
168
169     @Override
170     public String getServiceInterfaceName(String namespace, String localName) {
171         throw new UnsupportedOperationException();
172     }
173 }