use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerDomainsAction method doExecute.
protected Object doExecute() throws Exception {
validateContainerName(container);
Container found = FabricCommand.getContainer(fabricService, container);
List<String> domains = found.getJmxDomains();
for (String domain : domains) {
System.out.println(domain);
}
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerEditJvmOptionsAction method doExecute.
protected Object doExecute() throws Exception {
validateContainerName(container);
if (!FabricCommand.doesContainerExist(fabricService, container)) {
System.out.println("Container " + container + " does not exists!");
return null;
}
Container containerInstance = FabricCommand.getContainerIfExists(fabricService, container);
String type = containerInstance.getType();
if (!"karaf".equals(type)) {
System.out.println("Sorry, currently only \"karaf\" type container are supported");
return null;
}
// read current jvm values
FabricManager fabricManager = new FabricManager(fabricService);
if (full) {
String jmxUrl = null;
JMXConnector connector = null;
MBeanServerConnection remote = null;
HashMap<String, String[]> authenticationData = null;
jmxUrl = containerInstance.getJmxUrl();
authenticationData = prepareAuthenticationData();
try {
connector = connectOrRetry(authenticationData, jmxUrl);
} catch (Exception e) {
username = null;
password = null;
System.out.println("Operation Failed. Check logs.");
log.error("Unable to connect to JMX Server", e);
return null;
}
ObjectName objName = new ObjectName(JAVA_LANG_OBJECT_NAME);
try {
remote = connector.getMBeanServerConnection();
String[] arguments = (String[]) remote.getAttribute(objName, "InputArguments");
String output = Arrays.toString(arguments);
output = output.replaceAll(",", "");
output = output.substring(1, output.length() - 1);
System.out.println(output);
} catch (Exception e) {
System.out.println("Operation Failed. Check logs.");
log.error("Unable to fetch child jvm opts", e);
}
try {
connector.close();
} catch (IOException e) {
log.error("Errors closing remote MBean connection", e);
}
} else {
try {
String output = fabricManager.getJvmOpts(container);
if ("Inapplicable".equals(output)) {
String message = container + " jvmOpts cannot be handled within Fabric. You have to set required values directly in startup scripts.";
System.out.println(message);
log.error(message);
return null;
}
if (jvmOptions == null) {
System.out.println(output);
} else {
fabricManager.setJvmOpts(container, jvmOptions);
System.out.println("Operation succeeded. New JVM flags will be loaded at the next start of " + container + " container");
log.info("Updated JVM flags for container {}", container);
}
} catch (Exception e) {
System.out.println("Operation Failed. Check logs.");
log.error("Unable to set ssh jvm opts", e);
}
}
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class JavaContainers method getJavaContainerArtifacts.
public static Map<String, Parser> getJavaContainerArtifacts(FabricService fabric, List<Profile> profileList, DownloadManager downloadManager) throws Exception {
Map<String, Parser> artifacts = new TreeMap<String, Parser>();
for (Profile profile : profileList) {
Map<String, Parser> profileArtifacts = AgentUtils.getProfileArtifacts(fabric, downloadManager, profile);
artifacts.putAll(profileArtifacts);
appendMavenDependencies(artifacts, profile);
}
return artifacts;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ProjectDeployerImpl method resolveProfileDeployments.
private DeployResults resolveProfileDeployments(ProjectRequirements requirements, FabricService fabric, Profile profile, ProfileBuilder builder, boolean mergeWithOldProfile) throws Exception {
DependencyDTO rootDependency = requirements.getRootDependency();
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
if (!mergeWithOldProfile) {
// If we're not merging with the old profile, then create a dummy empty profile to merge with instead.
ProfileBuilder emptyProfile = ProfileBuilder.Factory.create(profile.getVersion(), profile.getId()).setOverlay(true);
profile = emptyProfile.getProfile();
}
if (rootDependency != null) {
// as a hack lets just add this bundle in
LOG.info("Got root: " + rootDependency);
List<String> parentIds = profile.getParentIds();
Profile overlay = profileService.getOverlayProfile(profile);
String bundleUrl = rootDependency.toBundleUrlWithType();
LOG.info("Using resolver to add extra features and bundles on " + bundleUrl);
List<String> features = new ArrayList<String>(profile.getFeatures());
List<String> bundles = new ArrayList<String>(profile.getBundles());
List<String> optionals = new ArrayList<String>(profile.getOptionals());
if (requirements.getFeatures() != null) {
features.addAll(requirements.getFeatures());
}
if (requirements.getBundles() != null) {
bundles.addAll(requirements.getBundles());
}
bundles.add(bundleUrl);
LOG.info("Adding bundle: " + bundleUrl);
// TODO we maybe should detect a karaf based container in a nicer way than this?
boolean isKarafContainer = parentIds.contains("karaf") || parentIds.contains("containers-karaf");
boolean addBundleDependencies = Objects.equal("bundle", rootDependency.getType()) || isKarafContainer;
if (addBundleDependencies && requirements.isUseResolver()) {
// lets build up a list of all current active features and bundles along with all discovered features
List<Feature> availableFeatures = new ArrayList<Feature>();
addAvailableFeaturesFromProfile(availableFeatures, fabric, overlay);
Set<String> currentBundleLocations = new HashSet<>();
currentBundleLocations.addAll(bundles);
// lets add the current features
DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabric, executorService);
Set<Feature> currentFeatures = AgentUtils.getFeatures(fabric, downloadManager, overlay);
addBundlesFromProfile(currentBundleLocations, overlay);
List<String> parentProfileIds = requirements.getParentProfiles();
if (parentProfileIds != null) {
for (String parentProfileId : parentProfileIds) {
Profile parentProfile = profileService.getProfile(profile.getVersion(), parentProfileId);
Profile parentOverlay = profileService.getOverlayProfile(parentProfile);
Set<Feature> parentFeatures = AgentUtils.getFeatures(fabric, downloadManager, parentOverlay);
currentFeatures.addAll(parentFeatures);
addAvailableFeaturesFromProfile(availableFeatures, fabric, parentOverlay);
addBundlesFromProfile(currentBundleLocations, parentOverlay);
}
}
// lets add all known features from the known repositories
for (DependencyDTO dependency : rootDependency.getChildren()) {
if ("test".equals(dependency.getScope()) || "provided".equals(dependency.getScope())) {
continue;
}
if ("jar".equals(dependency.getType())) {
String match = getAllServiceMixBundles().get(dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion());
if (match != null) {
LOG.info("Replacing artifact " + dependency + " with servicemix bundle " + match);
String[] parts = match.split(":");
dependency.setGroupId(parts[0]);
dependency.setArtifactId(parts[1]);
dependency.setVersion(parts[2]);
dependency.setType("bundle");
}
}
String prefix = dependency.toBundleUrlWithoutVersion();
Feature feature = findFeatureWithBundleLocationPrefix(currentFeatures, prefix);
if (feature != null) {
LOG.info("Feature is already is in the profile " + feature.getId() + " for " + dependency.toBundleUrl());
} else {
feature = findFeatureWithBundleLocationPrefix(availableFeatures, prefix);
if (feature != null) {
String name = feature.getName();
if (features.contains(name)) {
LOG.info("Feature is already added " + name + " for " + dependency.toBundleUrl());
} else {
LOG.info("Found a matching feature for bundle " + dependency.toBundleUrl() + ": " + feature.getId());
features.add(name);
}
} else {
String bundleUrlWithType = dependency.toBundleUrlWithType();
String foundBundleUri = findBundleUri(currentBundleLocations, prefix);
if (foundBundleUri != null) {
LOG.info("Bundle already included " + foundBundleUri + " for " + bundleUrlWithType);
} else {
boolean ignore = false;
String bundleWithoutMvnPrefix = getMavenCoords(bundleUrlWithType);
for (String ignoreBundlePrefix : RESOLVER_IGNORE_BUNDLE_PREFIXES) {
if (bundleWithoutMvnPrefix.startsWith(ignoreBundlePrefix)) {
ignore = true;
break;
}
}
if (ignore) {
LOG.info("Ignoring bundle: " + bundleUrlWithType);
} else {
boolean optional = dependency.isOptional();
LOG.info("Adding " + (optional ? "optional " : "") + " bundle: " + bundleUrlWithType);
if (optional) {
optionals.add(bundleUrlWithType);
} else {
bundles.add(bundleUrlWithType);
}
}
}
}
}
}
// Modify the profile through the {@link ProfileBuilder}
builder.setOptionals(optionals).setFeatures(features);
}
builder.setBundles(bundles);
}
profile = profileService.updateProfile(builder.getProfile());
Integer minimumInstances = requirements.getMinimumInstances();
if (minimumInstances != null) {
FabricRequirements fabricRequirements = fabricService.get().getRequirements();
ProfileRequirements profileRequirements = fabricRequirements.getOrCreateProfileRequirement(profile.getId());
profileRequirements.setMinimumInstances(minimumInstances);
fabricRequirements.setVersion(requirements.getVersion());
fabricService.get().setRequirements(fabricRequirements);
}
// lets find a hawtio profile and version
String profileUrl = findHawtioUrl(fabric);
if (profileUrl == null) {
profileUrl = "/";
}
if (!profileUrl.endsWith("/")) {
profileUrl += "/";
}
String profilePath = Profiles.convertProfileIdToPath(profile.getId());
profileUrl += "index.html#/wiki/branch/" + profile.getVersion() + "/view/fabric/profiles/" + profilePath;
return new DeployResults(profile, profileUrl);
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ProjectDeployerTest method setUp.
@Before
public void setUp() throws Exception {
URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
basedir = System.getProperty("basedir", ".");
String karafRoot = basedir + "/target/karaf";
System.setProperty("karaf.root", karafRoot);
System.setProperty("karaf.data", karafRoot + "/data");
sfb = new ZKServerFactoryBean();
delete(sfb.getDataDir());
delete(sfb.getDataLogDir());
sfb.setPort(9123);
sfb.afterPropertiesSet();
int zkPort = sfb.getClientPortAddress().getPort();
LOG.info("Connecting to ZK on port: " + zkPort);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
// setup a local and remote git repo
File root = new File(basedir + "/target/git").getCanonicalFile();
delete(root);
new File(root, "remote").mkdirs();
remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
new File(root, "local").mkdirs();
git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", remoteUrl);
config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
config.save();
runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))).andReturn("").anyTimes();
EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
EasyMock.replay(runtimeProperties);
FabricGitServiceImpl gitService = new FabricGitServiceImpl();
gitService.bindRuntimeProperties(runtimeProperties);
gitService.activate();
gitService.setGitForTesting(git);
/*
dataStore = new GitDataStoreImpl();
dataStore.bindCurator(curator);
dataStore.bindGitService(gitService);
dataStore.bindRuntimeProperties(runtimeProperties);
dataStore.bindConfigurer(new Configurer() {
@Override
public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
@Override
public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
});
Map<String, Object> datastoreProperties = new HashMap<String, Object>();
datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
dataStore.activate(datastoreProperties);
*/
fabricService = new FabricServiceImpl();
// fabricService.bindDataStore(dataStore);
fabricService.bindRuntimeProperties(runtimeProperties);
fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port"));
fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk"));
fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver());
fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver());
fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver());
fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver());
fabricService.activateComponent();
projectDeployer = new ProjectDeployerImpl();
projectDeployer.bindFabricService(fabricService);
projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer());
// dataStore.getDefaultVersion();
String defaultVersion = null;
assertEquals("defaultVersion", "1.0", defaultVersion);
// now lets import some data - using the old non-git file layout...
String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import";
assertFolderExists(importPath);
dataStore.importFromFileSystem(importPath);
assertHasVersion(defaultVersion);
}
Aggregations