use of io.fabric8.api.PatchException in project fabric8 by jboss-fuse.
the class ServiceImpl method download.
@Override
public Iterable<Patch> download(URL url) {
if ("file".equals(url.getProtocol())) {
// ENTESB-4992: prevent adding non existing files or directories
try {
if (!new File(url.toURI()).isFile()) {
throw new PatchException("Path " + url.getPath() + " doesn't exist or is not a file");
}
} catch (URISyntaxException e) {
throw new PatchException(e.getMessage(), e);
}
}
try {
List<PatchData> patchesData = patchManagement.fetchPatches(url);
List<Patch> patches = new ArrayList<>(patchesData.size());
for (PatchData patchData : patchesData) {
Patch patch = patchManagement.trackPatch(patchData);
patches.add(patch);
}
return patches;
} catch (PatchException e) {
throw e;
} catch (Exception e) {
throw new PatchException("Unable to download patch from url " + url, e);
}
}
use of io.fabric8.api.PatchException in project fabric8 by jboss-fuse.
the class ServiceImpl method checkStandaloneChild.
/**
* Check if this is installation in @{link {@link io.fabric8.patch.management.EnvType#STANDALONE_CHILD}}
* - in this case the patch has to be installed in root first
* @param patches
*/
private void checkStandaloneChild(Collection<Patch> patches) {
if (patchManagement.isStandaloneChild()) {
for (Patch patch : patches) {
if (patch.getResult() == null) {
throw new PatchException(String.format("Patch '%s' should be installed in parent container first", patch.getPatchData().getId()));
} else {
List<String> bases = patch.getResult().getKarafBases();
boolean isInstalledInRoot = false;
for (String base : bases) {
String[] coords = base.split("\\s*\\|\\s*");
if (coords.length == 2 && coords[1].trim().equals(System.getProperty("karaf.home"))) {
isInstalledInRoot = true;
}
}
if (!isInstalledInRoot) {
throw new PatchException(String.format("Patch '%s' should be installed in parent container first", patch.getPatchData().getId()));
}
}
}
}
}
use of io.fabric8.api.PatchException in project fabric8 by jboss-fuse.
the class ServiceImpl method applyChanges.
private void applyChanges(Map<Bundle, String> toUpdate) throws BundleException, IOException {
List<Bundle> toStop = new ArrayList<Bundle>();
Map<Bundle, String> lessToUpdate = new HashMap<>();
for (Bundle b : toUpdate.keySet()) {
if (b.getState() != Bundle.UNINSTALLED) {
toStop.add(b);
lessToUpdate.put(b, toUpdate.get(b));
}
}
while (!toStop.isEmpty()) {
List<Bundle> bs = getBundlesToDestroy(toStop);
for (Bundle bundle : bs) {
String hostHeader = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
if (hostHeader == null && (bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STARTING)) {
if (!"org.ops4j.pax.url.mvn".equals(bundle.getSymbolicName())) {
bundle.stop();
}
}
toStop.remove(bundle);
}
}
// eagerly load some classes
try {
getClass().getClassLoader().loadClass(Parser.class.getName());
getClass().getClassLoader().loadClass(Clause.class.getName());
getClass().getClassLoader().loadClass(Attribute.class.getName());
getClass().getClassLoader().loadClass(Directive.class.getName());
getClass().getClassLoader().loadClass(RefreshListener.class.getName());
} catch (Exception ignored) {
}
Set<Bundle> toRefresh = new HashSet<Bundle>();
Set<Bundle> toStart = new HashSet<Bundle>();
for (Map.Entry<Bundle, String> e : lessToUpdate.entrySet()) {
Bundle bundle = e.getKey();
if (!"org.ops4j.pax.url.mvn".equals(bundle.getSymbolicName())) {
System.out.println("updating: " + bundle.getSymbolicName());
try {
BundleUtils.update(bundle, new URL(e.getValue()));
} catch (BundleException ex) {
System.err.println("Failed to update: " + bundle.getSymbolicName() + ", due to: " + e);
}
toStart.add(bundle);
toRefresh.add(bundle);
}
}
findBundlesWithOptionalPackagesToRefresh(toRefresh);
findBundlesWithFragmentsToRefresh(toRefresh);
if (!toRefresh.isEmpty()) {
final CountDownLatch l = new CountDownLatch(1);
FrameworkListener listener = new RefreshListener(l);
FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
wiring.refreshBundles(toRefresh, listener);
try {
l.await();
} catch (InterruptedException e) {
throw new PatchException("Bundle refresh interrupted", e);
}
}
for (Bundle bundle : toStart) {
String hostHeader = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
if (hostHeader == null) {
try {
bundle.start();
} catch (BundleException e) {
System.err.println("Failed to start: " + bundle.getSymbolicName() + ", due to: " + e);
}
}
}
}
use of io.fabric8.api.PatchException in project fabric8 by jboss-fuse.
the class ServiceImplTest method testCheckPrerequisitesMultiplePatches.
@Test
public void testCheckPrerequisitesMultiplePatches() throws IOException {
ServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch1.patch"));
Collection<Patch> patches = new LinkedList<Patch>();
patches.add(service.getPatch("patch3"));
// this should not throw a PatchException
service.checkPrerequisites(patches);
patches.add(service.getPatch("patch2"));
try {
service.checkPrerequisites(patches);
fail("Should not pass check if one of the patches is missing a requirement");
} catch (PatchException e) {
// graciously do nothing, this is OK
}
}
use of io.fabric8.api.PatchException in project fabric8 by jboss-fuse.
the class ServiceImplTest method testCheckPrerequisitesSatisfied.
@Test
public void testCheckPrerequisitesSatisfied() throws IOException {
ServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch3.patch"));
Patch patch = service.getPatch("patch3");
assertNotNull(patch);
// this should not throw a PatchException
service.checkPrerequisites(patch);
}
Aggregations