Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.brooklyn.entity.osgi.karaf;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.TabularData;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.core.annotation.Effector;
import org.apache.brooklyn.core.annotation.EffectorParam;
import org.apache.brooklyn.core.feed.ConfigToAttributes;
import org.apache.brooklyn.entity.java.JmxSupport;
import org.apache.brooklyn.entity.software.base.SoftwareProcessImpl;
import org.apache.brooklyn.feed.jmx.JmxAttributePollConfig;
import org.apache.brooklyn.feed.jmx.JmxFeed;
import org.apache.brooklyn.feed.jmx.JmxHelper;
import org.apache.brooklyn.feed.jmx.JmxValueFunctions;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.repeat.Repeater;
import org.osgi.jmx.JmxConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
/**
* This sets up a Karaf OSGi container
*/
public class KarafContainerImpl extends SoftwareProcessImpl implements KarafContainer {
// TODO Better way of setting/overriding defaults for config keys that are defined in super class SoftwareProcess
private static final Logger LOG = LoggerFactory.getLogger(KarafContainerImpl.class);
public static final String KARAF_ADMIN = "org.apache.karaf:type=admin,name=%s";
public static final String KARAF_FEATURES = "org.apache.karaf:type=features,name=%s";
public static final String OSGI_BUNDLE_STATE = "osgi.core:type=bundleState,version=1.5";
public static final String OSGI_FRAMEWORK = "osgi.core:type=framework,version=1.5";
public static final String OSGI_COMPENDIUM = "osgi.compendium:service=cm,version=1.3";
protected JmxHelper jmxHelper;
private JmxFeed jmxFeed;
public KarafContainerImpl() {
super();
}
@Override
public Class getDriverInterface() {
return KarafDriver.class;
}
@Override
public KarafDriver getDriver() {
return (KarafDriver) super.getDriver();
}
@Override
public void init() {
super.init();
new JmxSupport(this, null).recommendJmxRmiCustomAgent();
}
@Override
protected void postDriverStart() {
super.postDriverStart();
uploadPropertyFiles(getConfig(NAMED_PROPERTY_FILES));
jmxHelper = new JmxHelper(this);
jmxHelper.connect(0); // i.e. don't block
}
@Override
protected void connectSensors() {
super.connectSensors();
//FIXME should have a better way of setting config -- firstly, not here!
//preferred style is to have config auto-applied to attributes, and have default values in their definition, not here
//use of "properties.{user,password}" is non-standard; is that requried? use default jmxUser, jmxPassword flags?
sensors().set(JMX_CONTEXT, String.format("karaf-%s", getConfig(KARAF_NAME.getConfigKey())));
ConfigToAttributes.apply(this);
ObjectName karafAdminObjectName = JmxHelper.createObjectName(String.format(KARAF_ADMIN, getConfig(KARAF_NAME.getConfigKey())));
jmxFeed = JmxFeed.builder()
.entity(this)
.helper(jmxHelper)
.period(500, TimeUnit.MILLISECONDS)
.pollAttribute(new JmxAttributePollConfig