use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class DetectingGatewayTest method startBrokers.
@Before
public void startBrokers() {
for (int i = 0; i < 2; i++) {
// create a broker..
String name = "broker" + i;
Broker broker = createBroker(name);
ServiceControl.start(broker);
brokers.add(broker);
// Add a service map entry for the broker.
ServiceDTO details = new ServiceDTO();
details.setId(name);
details.setVersion("1.0");
details.setContainer("testing");
details.setBundleName("none");
details.setBundleVersion("1.0");
List<String> services = Arrays.asList("stomp://localhost:" + portOfBroker(i), "mqtt://localhost:" + portOfBroker(i), "amqp://localhost:" + portOfBroker(i), "tcp://localhost:" + portOfBroker(i));
details.setServices(services);
serviceMap.serviceUpdated(name, details);
println(String.format("Broker %s is exposing: %s", name, services));
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class Offline method applyPatch.
protected void applyPatch(PatchData patch, ZipFile zipFile, File storage) throws IOException {
log(DEBUG, "Applying patch: " + patch.getId() + " / " + patch.getDescription());
File startupFile = new File(karafBase, "etc/startup.properties");
File overridesFile = new File(karafBase, "etc/overrides.properties");
List<String> startup = readLines(new File(karafBase, "etc/startup.properties"));
List<String> overrides = readLines(overridesFile);
List<Artifact> toExtract = new ArrayList<Artifact>();
List<Artifact> toDelete = new ArrayList<Artifact>();
for (String bundle : patch.getBundles()) {
Artifact artifact = mvnurlToArtifact(bundle, true);
if (artifact == null) {
continue;
}
// Compute patch bundle version and range
VersionRange range;
Version oVer = VersionTable.getVersion(artifact.getVersion());
String vr = patch.getVersionRange(bundle);
String override;
if (vr != null && !vr.isEmpty()) {
override = bundle + OVERRIDE_RANGE + vr;
range = VersionRange.parseVersionRange(vr);
} else {
override = bundle;
Version v1 = new Version(oVer.getMajor(), oVer.getMinor(), 0);
Version v2 = new Version(oVer.getMajor(), oVer.getMinor() + 1, 0);
range = new VersionRange(false, v1, v2, true);
}
// Process overrides.properties
boolean matching = false;
boolean added = false;
for (int i = 0; i < overrides.size(); i++) {
String line = overrides.get(i).trim();
if (!line.isEmpty() && !line.startsWith("#")) {
Artifact overrideArtifact = mvnurlToArtifact(line, true);
if (overrideArtifact != null) {
Version ver = VersionTable.getVersion(overrideArtifact.getVersion());
if (isSameButVersion(artifact, overrideArtifact) && range.contains(ver)) {
matching = true;
if (ver.compareTo(oVer) < 0) {
// Replace old override with the new one
overrides.set(i, override);
if (!added) {
log(DEBUG, "Replacing with artifact: " + override);
added = true;
}
// Remove old file
toDelete.add(overrideArtifact);
toExtract.remove(overrideArtifact);
}
}
} else {
log(WARN, "Unable to convert to artifact: " + line);
}
}
}
// If there was not matching bundles, add it
if (!matching) {
overrides.add(override);
log(DEBUG, "Adding artifact: " + override);
}
// Process startup.properties
for (int i = 0; i < startup.size(); i++) {
String line = startup.get(i).trim();
if (!line.isEmpty() && !line.startsWith("#")) {
int index = line.indexOf('=');
String mvnUrl = Utils.pathToMvnurl(line.substring(0, index));
if (mvnUrl != null) {
Artifact startupArtifact = mvnurlToArtifact(mvnUrl, true);
if (startupArtifact != null) {
Version ver = VersionTable.getVersion(startupArtifact.getVersion());
if (isSameButVersion(artifact, startupArtifact) && range.contains(ver)) {
matching = true;
// Now check versions
if (ver.compareTo(oVer) < 0) {
line = artifact.getPath() + line.substring(index);
startup.set(i, line);
log(DEBUG, "Overwriting startup.properties with: " + artifact);
added = true;
}
}
}
}
}
}
// Extract artifact
if (!matching || added) {
toExtract.add(artifact);
}
}
// Extract / delete artifacts if needed
if (zipFile != null) {
for (Artifact artifact : toExtract) {
log(DEBUG, "Extracting artifact: " + artifact);
ZipEntry entry = zipFile.getEntry("repository/" + artifact.getPath());
if (entry == null) {
log(ERROR, "Could not find artifact in patch zip: " + artifact);
continue;
}
File f = new File(karafBase, "system/" + artifact.getPath());
if (!f.isFile()) {
f.getParentFile().mkdirs();
InputStream fis = zipFile.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(f);
try {
IOUtils.copy(fis, fos);
} finally {
IOUtils.closeQuietly(fis);
IOUtils.closeQuietly(fos);
}
}
}
for (Artifact artifact : toDelete) {
String fileName = artifact.getPath();
File file = new File(karafBase, "system/" + fileName);
if (file.exists()) {
log(DEBUG, "Removing old artifact " + artifact);
file.delete();
} else {
log(WARN, "Could not find: " + file);
}
}
}
overrides = new ArrayList<String>(new HashSet<String>(overrides));
Collections.sort(overrides);
writeLines(overridesFile, overrides);
writeLines(startupFile, startup);
// update the remaining patch files (using either the patch ZIP file or the patch storage location)
if (zipFile != null) {
patchFiles(patch, zipFile);
} else if (storage != null) {
patchFiles(patch, storage);
} else {
throw new PatchException("Unable to update patch files: no access to patch ZIP file or patch storage location");
}
if (patch.getMigratorBundle() != null) {
Artifact artifact = mvnurlToArtifact(patch.getMigratorBundle(), true);
if (artifact != null) {
// Copy it to the deploy dir
File src = new File(karafBase, "system/" + artifact.getPath());
File target = new File(new File(karafBase, "deploy"), artifact.getArtifactId() + ".jar");
copy(src, target);
}
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class Offline method extractPatch.
protected List<PatchData> extractPatch(ZipFile zipFile) throws IOException {
List<PatchData> patches = new ArrayList<PatchData>();
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
String entryName = entry.getName();
if (entryName.endsWith(".patch") && !entryName.contains("/")) {
InputStream fis = zipFile.getInputStream(entry);
try {
PatchData patch = PatchData.load(fis);
patches.add(patch);
} finally {
IOUtils.closeQuietly(fis);
}
}
}
}
return patches;
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class JsonRuleBaseReader method parseJson.
/**
* Will try to parse the {@link InputStream} which is expected to be in the following
* JSON format:
* <pre>
* { "rulebase" : [
* { "rule": "/foo/{path}", "to": "https://foo.com/cheese/{path}"},
* { "rule": "/customers/{id}/address/{addressId}", "to": "http://another.com/addresses/{addressId}/customer/{id}"}
* ]
* }
* </pre>
*
* <strong>Note that the passed-in {@link InputStream} will be closed by this method</strong>. This
* is a little unusual as normally the closing is the responsibility of the party that created the
* InputStream, but in this case we decided handling this is more user friendly.
*
* @param in the {@link InputStream} stream to read.
* @return {@code Map} where the key maps to the 'rule' in the JSON, and the value maps to 'to'.
*/
public static Map<String, HttpProxyRule> parseJson(InputStream in) {
chechNotNull(in);
HashMap<String, HttpProxyRule> map = new HashMap<String, HttpProxyRule>();
try {
JsonNode config = OM.readTree(in);
JsonNode globalCookiePath = config.get("cookiePath");
JsonNode globalDomain = config.get("cookieDomain");
for (JsonNode entry : getRuleBase(config)) {
String rule = entry.get("rule").asText();
map.put(rule, new HttpProxyRule(rule).to(entry.get("to").asText()).setCookiePath(getGlobal(entry, globalCookiePath, "cookiePath")).setCookieDomain(getGlobal(entry, globalDomain, "cookieDomain")));
}
return map;
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
safeClose(in);
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class InternalServiceRegistar method getService.
@Override
public Service getService(String serviceName) {
Map<String, String> env = System.getenv();
String prefix = serviceName.toUpperCase();
String serviceHost = env.get(prefix + HOST_SUFFIX);
String defaultPortName = prefix + SERVICE_PORT;
String namedPortPrefix = defaultPortName + "_";
List<ServicePort> servicePorts = new ArrayList<>();
for (Map.Entry<String, String> entry : env.entrySet()) {
String key = entry.getKey();
if (key.startsWith(namedPortPrefix)) {
String name = key.substring(namedPortPrefix.length());
String portValue = entry.getValue();
String protocolValue = env.get(key + "_" + PROTO_SUFFIX);
servicePorts.add(new ServicePortBuilder().withName(name.toLowerCase()).withPort(Integer.parseInt(portValue)).withProtocol(protocolValue != null ? protocolValue : "TCP").build());
}
}
// Check if we need to fallback to single port.
if (servicePorts.isEmpty()) {
String portValue = env.get(defaultPortName);
String protocolValue = env.get(defaultPortName + PROTO_SUFFIX);
servicePorts.add(new ServicePortBuilder().withPort(Integer.parseInt(portValue)).withProtocol(protocolValue != null ? protocolValue : "TCP").build());
}
return new ServiceBuilder().withNewMetadata().withName(serviceName).endMetadata().withNewSpec().withClusterIP(serviceHost).withPorts(servicePorts).endSpec().build();
}
Aggregations