2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.util.jolokia;
13 import javax.management.Attribute;
14 import javax.management.AttributeNotFoundException;
15 import javax.management.InstanceAlreadyExistsException;
16 import javax.management.InstanceNotFoundException;
17 import javax.management.ObjectName;
19 import org.jolokia.client.request.J4pExecRequest;
20 import org.jolokia.client.request.J4pReadRequest;
21 import org.jolokia.client.request.J4pWriteRequest;
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.ObjectNameUtil;
26 import org.opendaylight.controller.config.util.AttributeEntry;
27 import org.opendaylight.controller.config.util.ConfigTransactionClient;
30 public class ConfigTransactionJolokiaClient extends ListableJolokiaClient
31 implements ConfigTransactionClient {
33 private final ConfigRegistryJolokiaClient configRegistryJolokiaClient;
35 public ConfigTransactionJolokiaClient(String url,
36 ObjectName transactionControllerON,
37 ConfigRegistryJolokiaClient configRegistryJolokiaClient) {
38 super(url, transactionControllerON);
39 this.configRegistryJolokiaClient = configRegistryJolokiaClient;
42 public ObjectName getTransactionON() {
47 public CommitStatus commit() throws ConflictingVersionException,
49 return configRegistryJolokiaClient.commitConfig(objectName);
53 public ObjectName createModule(String moduleName, String instanceName)
54 throws InstanceAlreadyExistsException {
55 J4pExecRequest execReq = new J4pExecRequest(objectName, "createModule",
56 moduleName, instanceName);
58 return extractObjectName(execute(execReq));
59 } catch (RuntimeException e) {
60 if (e.getMessage() != null
61 && e.getMessage().startsWith(
62 InstanceAlreadyExistsException.class.getName()))
63 throw new InstanceAlreadyExistsException();
69 public void destroyModule(ObjectName configBeanON) {
70 J4pExecRequest execReq = new J4pExecRequest(objectName,
71 "destroyModule(javax.management.ObjectName)", configBeanON);
76 public void destroyConfigBean(String moduleName, String instanceName)
77 throws InstanceNotFoundException {
78 destroyModule(ObjectNameUtil.createTransactionModuleON(
79 getTransactionName(), moduleName, instanceName));
83 public void abortConfig() {
84 J4pExecRequest execReq = new J4pExecRequest(objectName, "abortConfig");
89 public void validateConfig() throws ValidationException {
90 J4pExecRequest execReq = new J4pExecRequest(objectName,
96 public long getParentVersion() {
97 J4pReadRequest req = new J4pReadRequest(objectName, "ParentVersion");
98 return (Long) execute(req).getValue();
102 public long getVersion() {
103 J4pReadRequest req = new J4pReadRequest(objectName, "Version");
104 return (Long) execute(req).getValue();
107 public void setAttribute(ObjectName configBeanTransactionON, String key,
109 J4pWriteRequest req = new J4pWriteRequest(configBeanTransactionON, key,
113 } catch (RuntimeException e) {
114 if (e.getMessage() != null
115 && e.getMessage().startsWith(
116 AttributeNotFoundException.class.getName())) {
117 // try to fix wrong case
118 Map<String, AttributeEntry> allAttributes = getAttributes(configBeanTransactionON);
119 for (AttributeEntry attrib : allAttributes.values()) {
120 if (attrib.getKey().equalsIgnoreCase(key)) {
121 req = new J4pWriteRequest(configBeanTransactionON,
122 attrib.getKey(), value);
132 public Object getAttribute(ObjectName objectName, String key) {
133 return configRegistryJolokiaClient.getAttribute(objectName, key);
136 public ObjectName getAttributeON(ObjectName objectName, String key) {
137 return configRegistryJolokiaClient.getAttributeON(objectName, key);
141 public String getTransactionName() {
142 return ObjectNameUtil.getTransactionName(objectName);
146 public void validateBean(ObjectName rwON) throws ValidationException {
147 J4pExecRequest req = new J4pExecRequest(rwON, "validate", new Object[0]);
152 public void assertVersion(int expectedParentVersion,
153 int expectedCurrentVersion) {
154 if (expectedParentVersion != getParentVersion()) {
155 throw new IllegalStateException();
157 if (expectedCurrentVersion != getVersion()) {
158 throw new IllegalStateException();
163 public void setAttribute(ObjectName on, String jmxName, Attribute attribute) {
164 throw new UnsupportedOperationException();
167 // TODO: implement or deprecate
169 public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
170 throw new UnsupportedOperationException();
174 public void saveServiceReference(String serviceInterfaceName, String refName, ObjectName objectName) throws InstanceNotFoundException {
175 throw new UnsupportedOperationException();
179 public boolean removeServiceReference(String serviceInterfaceName, String refName) {
180 throw new UnsupportedOperationException();
184 public void removeAllServiceReferences() {
185 throw new UnsupportedOperationException();
189 public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceName, String refName) {
190 throw new UnsupportedOperationException();
194 public Map<String, Map<String, ObjectName>> getServiceMapping() {
195 throw new UnsupportedOperationException();
199 public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceName) {
200 throw new UnsupportedOperationException();
204 public Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
205 throw new UnsupportedOperationException();
209 public String getServiceInterfaceName(String namespace, String localName) {
210 throw new UnsupportedOperationException();
214 public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException {
215 throw new UnsupportedOperationException();