use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class VersionImpl method getRequiredProfile.
@Override
public Profile getRequiredProfile(String profileId) {
Profile profile = profiles.get(profileId);
IllegalStateAssertion.assertNotNull(profile, "Profile '" + profileId + "' does not exist in version: " + versionId);
return profile;
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class AutoScalers method requirementsSatisfied.
/**
* Returns true if the requirements are satisfied for the given profile requirements; updating the auto scale status
* accordingly
*/
public static boolean requirementsSatisfied(FabricService service, String version, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status) {
String profile = profileRequirement.getProfile();
List<String> dependentProfiles = profileRequirement.getDependentProfiles();
if (dependentProfiles != null) {
for (String dependentProfile : dependentProfiles) {
ProfileRequirements dependentProfileRequirements = requirements.getOrCreateProfileRequirement(dependentProfile);
Integer minimumInstances = dependentProfileRequirements.getMinimumInstances();
if (minimumInstances != null) {
List<Container> containers = Containers.aliveAndSuccessfulContainersForProfile(version, dependentProfile, service);
int dependentSize = containers.size();
if (minimumInstances > dependentSize) {
status.profileStatus(profile).missingDependency(dependentProfile, dependentSize, minimumInstances);
return false;
}
}
}
}
return true;
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class FabricCxfRegistrationHandler method registerApiEndpoint.
protected void registerApiEndpoint(Container container, ObjectName oName, String address, boolean started) {
String actualEndpointUrl = null;
try {
String url;
String id = container.getId();
if (isFullAddress(address)) {
url = toPublicAddress(id, address);
} else {
String cxfBus = getCxfServletPath(oName);
url = "${zk:" + id + "/http}" + cxfBus + address;
}
actualEndpointUrl = ZooKeeperUtils.getSubstitutedData(curator.get(), url);
// lets assume these locations are hard coded
// may be nice to discover from JMX one day
String apiDocPath = "/api-docs";
String wsdlPath = "?wsdl";
String wadlPath = "?_wadl";
Version version = container.getVersion();
String versionId = version != null ? version.getId() : null;
String json = "{\"id\":" + JsonHelper.jsonEncodeString(id) + ", \"container\":" + JsonHelper.jsonEncodeString(id) + ", \"version\":" + JsonHelper.jsonEncodeString(versionId) + ", \"services\":[" + JsonHelper.jsonEncodeString(url) + "]" + ", \"objectName\":" + JsonHelper.jsonEncodeString(oName.toString()) + "";
boolean rest = false;
if (booleanAttribute(oName, "isWADL")) {
rest = true;
json += ", \"wadl\":" + JsonHelper.jsonEncodeString(wadlPath);
}
if (booleanAttribute(oName, "isSwagger")) {
rest = true;
json += ", \"apidocs\":" + JsonHelper.jsonEncodeString(apiDocPath);
}
if (booleanAttribute(oName, "isWSDL")) {
json += ", \"wsdl\":" + JsonHelper.jsonEncodeString(wsdlPath);
}
json += "}";
String path = getPath(container, oName, address, rest);
LOGGER.info("Registered CXF API at " + path + " JSON: " + json);
if (!started && !rest) {
LOGGER.warn("Since the CXF service isn't started, this could really be a REST endpoint rather than WSDL at " + path);
}
registeredZkPaths.add(path);
registeredUrls.put(oName.toString(), address);
ZooKeeperUtils.setData(curator.get(), path, json, CreateMode.EPHEMERAL);
} catch (Exception e) {
LOGGER.error("Failed to register API endpoint for {}.", actualEndpointUrl, e);
}
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class MQServiceImpl method createOrUpdateMQProfile.
@Override
public Profile createOrUpdateMQProfile(String versionId, String profileId, String brokerName, Map<String, String> configs, boolean replicated) {
Version version = profileService.getRequiredVersion(versionId);
String parentProfileName = null;
if (configs != null && configs.containsKey("parent")) {
parentProfileName = configs.remove("parent");
}
if (Strings.isNullOrBlank(parentProfileName)) {
parentProfileName = replicated ? MQ_PROFILE_REPLICATED : MQ_PROFILE_BASE;
}
Profile parentProfile = version.getRequiredProfile(parentProfileName);
if (brokerName == null || profileId == null) {
return parentProfile;
}
String pidName = getBrokerPID(brokerName);
// lets check we have a config value
ProfileBuilder builder;
Profile overlay;
// create a profile if it doesn't exist
Map<String, String> config = null;
boolean create = !version.hasProfile(profileId);
if (create) {
builder = ProfileBuilder.Factory.create(versionId, profileId);
if (parentProfile != null) {
builder.addParent(parentProfile.getId());
}
overlay = profileService.getOverlayProfile(parentProfile);
} else {
Profile profile = version.getRequiredProfile(profileId);
builder = ProfileBuilder.Factory.createFrom(profile);
config = builder.getConfiguration(pidName);
overlay = profileService.getOverlayProfile(profile);
}
Map<String, String> parentProfileConfig = ProfileBuilder.Factory.createFrom(overlay).getConfiguration(MQ_PID_TEMPLATE);
if (config == null) {
config = parentProfileConfig;
}
if (configs != null && "true".equals(configs.get("ssl"))) {
// Only generate the keystore file if it does not exist.
// [TOOD] Fix direct data access! This should be part of the ProfileBuilder
byte[] keystore = overlay.getFileConfiguration("keystore.jks");
if (keystore == null) {
try {
String host = configs.get("keystore.cn");
if (host == null) {
host = configs.get(GROUP);
if (host == null) {
host = "localhost";
}
configs.put("keystore.cn", host);
}
String password = configs.get("keystore.password");
if (password == null) {
password = generatePassword(8);
configs.put("keystore.password", password);
}
File keystoreFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
keystoreFile.delete();
LOG.info("Generating ssl keystore...");
int rc = system("keytool", "-genkey", "-storetype", "JKS", "-storepass", password, "-keystore", keystoreFile.getCanonicalPath(), "-keypass", password, "-alias", host, "-keyalg", "RSA", "-keysize", "4096", "-dname", String.format("cn=%s", host), "-validity", "3650");
if (rc != 0) {
throw new IOException("keytool failed with exit code: " + rc);
}
keystore = Files.readBytes(keystoreFile);
keystoreFile.delete();
LOG.info("Keystore generated");
builder.addFileConfiguration("keystore.jks", keystore);
configs.put("keystore.file", "profile:keystore.jks");
} catch (IOException e) {
LOG.error("Failed to generate keystore.jks: " + e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
// [TOOD] Fix direct data access! This should be part of the ProfileBuilder
byte[] truststore = overlay.getFileConfiguration("truststore.jks");
if (truststore == null && configs.get("keystore.password") != null) {
try {
String password = configs.get("truststore.password");
if (password == null) {
password = configs.get("keystore.password");
configs.put("truststore.password", password);
}
File keystoreFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
Files.writeToFile(keystoreFile, keystore);
File certFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
certFile.delete();
LOG.info("Exporting broker certificate to create truststore.jks");
int rc = system("keytool", "-exportcert", "-rfc", "-keystore", keystoreFile.getCanonicalPath(), "-storepass", configs.get("keystore.password"), "-alias", configs.get("keystore.cn"), "--file", certFile.getCanonicalPath());
keystoreFile.delete();
if (rc != 0) {
throw new IOException("keytool failed with exit code: " + rc);
}
LOG.info("Creating truststore.jks");
File truststoreFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
truststoreFile.delete();
rc = system("keytool", "-importcert", "-noprompt", "-keystore", truststoreFile.getCanonicalPath(), "-storepass", password, "--file", certFile.getCanonicalPath());
certFile.delete();
if (rc != 0) {
throw new IOException("keytool failed with exit code: " + rc);
}
truststore = Files.readBytes(truststoreFile);
truststoreFile.delete();
builder.addFileConfiguration("truststore.jks", truststore);
configs.put("truststore.file", "profile:truststore.jks");
} catch (IOException e) {
LOG.error("Failed to generate truststore.jks due: " + e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
config.put("broker-name", brokerName);
if (configs != null) {
config.putAll(configs);
}
// lets check we've a bunch of config values inherited from the template
String[] propertiesToDefault = { CONFIG_URL, STANDBY_POOL, CONNECTORS };
for (String key : propertiesToDefault) {
if (config.get(key) == null) {
String defaultValue = parentProfileConfig.get(key);
if (Strings.isNotBlank(defaultValue)) {
config.put(key, defaultValue);
}
}
}
// config map is not from "official" profile, so it doesn't have to use felix' Properties class
builder.addConfiguration(pidName, config);
Profile profile = builder.getProfile();
return create ? profileService.createProfile(profile) : profileService.updateProfile(profile);
}
use of io.fabric8.api.Version in project fabric8 by jboss-fuse.
the class ProfileServiceImpl method getOverlayProfile.
@Override
public Profile getOverlayProfile(Profile profile) {
assertValid();
Profile overlayProfile;
synchronized (this) {
if (profile.isOverlay()) {
LOGGER.debug("getOverlayProfile, given profile is already an overlay: " + profile);
overlayProfile = profile;
} else {
String profileId = profile.getId();
String environment = runtimeProperties.get().getProperty(SystemProperties.FABRIC_ENVIRONMENT);
if (environment == null) {
// lets default to the environment from the current active
// set of profiles (e.g. docker or openshift)
environment = System.getProperty(SystemProperties.FABRIC_PROFILE_ENVIRONMENT);
}
Version version = getRequiredVersion(profile.getVersion());
ProfileBuilder builder = ProfileBuilder.Factory.create(profile.getVersion(), profileId);
builder.addOptions(new OverlayOptionsProvider(version, profile, environment));
overlayProfile = builder.getProfile();
// Log the overlay profile difference
if (LOGGER.isDebugEnabled()) {
OverlayAudit audit = getOverlayAudit();
synchronized (audit) {
Profile lastOverlay = audit.overlayProfiles.get(profileId);
if (lastOverlay == null) {
LOGGER.debug("Overlay" + Profiles.getProfileInfo(overlayProfile));
audit.overlayProfiles.put(profileId, overlayProfile);
} else if (!lastOverlay.equals(overlayProfile)) {
LOGGER.debug("Overlay" + Profiles.getProfileDifference(lastOverlay, overlayProfile));
audit.overlayProfiles.put(profileId, overlayProfile);
}
}
}
}
}
return overlayProfile;
}
Aggregations