use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class PushPullPolicyIT method pushLocalBranchBehind.
@Test
public void pushLocalBranchBehind() throws IOException, GitAPIException {
local.checkout().setName("1.1").setCreateBranch(false).call();
local.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD^").call();
assertTrue(local.status().call().isClean());
PullPushPolicy.PushPolicyResult result = policy.doPush(new GitContext(), CP);
assertNull(result.getLastException());
// push to only one remote, so one PushResult
PushResult pr = result.getPushResults().get(0);
assertThat(result.getAcceptedUpdates().size(), equalTo(5));
assertThat(pr.getRemoteUpdate("refs/heads/1.0").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
assertThat(pr.getRemoteUpdate("refs/heads/1.0.1").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
assertThat(pr.getRemoteUpdate("refs/heads/1.1").getStatus(), equalTo(RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD));
assertThat(pr.getRemoteUpdate("refs/heads/1.2").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
assertThat(pr.getRemoteUpdate("refs/heads/master").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
assertThat(pr.getRemoteUpdate("refs/tags/root").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
assertThat(result.getRejectedUpdates().size(), equalTo(1));
assertThat(result.getRejectedUpdates().get("refs/heads/1.1").getRemoteRefUpdate().getStatus(), equalTo(RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD));
assertTrue(local.status().call().isClean());
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class PushPullPolicyIT method remoteUpdateWhenLocalBranchIsAheadButAlreadyMerged.
@Test
public void remoteUpdateWhenLocalBranchIsAheadButAlreadyMerged() throws GitAPIException, IOException {
editVersion("1.1", 2, false);
local.checkout().setName("1.0").setCreateBranch(false).call();
PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
assertNull(result.getLastException());
List<String> versions = new ArrayList<>(result.getVersions());
// these are sorted (TreeSet)
assertThat(versions.size(), equalTo(5));
assertThat(versions.get(0), equalTo("1.0"));
assertThat(versions.get(1), equalTo("1.0.1"));
assertThat(versions.get(2), equalTo("1.1"));
assertThat(versions.get(3), equalTo("1.2"));
assertThat(versions.get(4), equalTo("master"));
List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
assertThat(localUpdateVersions.size(), equalTo(0));
// if remote commit is already present in local branch, which has additional commits, we have to push back
// to central repo
assertTrue(result.remoteUpdateRequired());
assertTrue(local.status().call().isClean());
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class Deployer method computeDeployment.
protected Deployment computeDeployment(DeploymentState dstate, DeploymentRequest request, SubsystemResolver resolver) throws IOException {
Deployment result = new Deployment();
Map<String, Set<Resource>> bundlesPerRegions = resolver.getBundlesPerRegions();
// Gather all regions, including old ones and new ones
Set<String> regions = new HashSet<>();
regions.addAll(dstate.state.managedBundles.keySet());
regions.addAll(bundlesPerRegions.keySet());
for (String region : regions) {
Deployer.RegionDeployment deployment = new Deployer.RegionDeployment();
// Get the list of bundles currently assigned in the region
Set<Long> managed = dstate.state.managedBundles.get(region);
if (managed == null) {
managed = Collections.emptySet();
}
// Compute the list of resources to deploy in the region
Set<Resource> bundlesInRegion = bundlesPerRegions.get(region);
List<Resource> toDeploy = bundlesInRegion != null ? new ArrayList<>(bundlesInRegion) : new ArrayList<Resource>();
// as either to ignore or delete
for (long bundleId : managed) {
// Look for the installed bundle
Bundle bundle = dstate.bundles.get(bundleId);
// Bundle has been manually uninstalled ?
if (bundle != null) {
// Look for a matching resource
Resource resource = null;
for (Resource res : toDeploy) {
if (bundle.getSymbolicName().equals(getSymbolicName(res)) && bundle.getVersion().equals(getVersion(res))) {
resource = res;
break;
}
}
// We found a matching bundle
if (resource != null) {
String uri = getUri(resource);
// and flag it as to update
if (uri != null && isUpdateable(uri)) {
// Always update snapshots
if (Constants.UPDATE_SNAPSHOTS_ALWAYS.equalsIgnoreCase(request.updateSnaphots)) {
LOGGER.debug("Update snapshot for " + bundle.getLocation());
deployment.toUpdate.put(bundle, resource);
} else if (Constants.UPDATE_SNAPSHOTS_CRC.equalsIgnoreCase(request.updateSnaphots)) {
// if the checksum are different
InputStream is = null;
try {
is = getBundleInputStream(resource, resolver.getProviders());
Long bpNewCrc = null;
try {
URI resourceURI = new URI(uri);
if ("blueprint".equals(resourceURI.getScheme())) {
InputStream bis = getBlueprintInputStream(is);
// original stream is closed in either case
if (bis != null) {
bpNewCrc = ChecksumUtils.checksum(bis);
is = bis;
} else {
// rewind FileInputStream, because we failed to read blueprint
// descriptor
is = getBundleInputStream(resource, resolver.getProviders());
}
}
} catch (URISyntaxException ignored) {
}
long newCrc = bpNewCrc != null ? bpNewCrc : ChecksumUtils.checksum(is);
long oldCrc = dstate.state.bundleChecksums.containsKey(bundle.getBundleId()) ? dstate.state.bundleChecksums.get(bundle.getBundleId()) : 0L;
if (newCrc != oldCrc) {
LOGGER.debug("New snapshot available for " + bundle.getLocation());
deployment.toUpdate.put(bundle, resource);
}
result.bundleChecksums.put(bundle.getBundleId(), newCrc);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignored) {
}
}
}
}
}
// We're done for this resource
toDeploy.remove(resource);
result.resToBnd.put(resource, bundle);
// There's no matching resource
// If the bundle is managed, we need to delete it
} else if (managed.contains(bundle.getBundleId())) {
deployment.toDelete.add(bundle);
}
}
}
// Second pass on remaining resources
for (Resource resource : toDeploy) {
TreeMap<Version, Bundle> matching = new TreeMap<>();
VersionRange range = new VersionRange(Macro.transform(request.bundleUpdateRange, getVersion(resource).toString()));
for (Bundle bundle : deployment.toDelete) {
if (bundle.getSymbolicName().equals(getSymbolicName(resource)) && range.contains(bundle.getVersion())) {
matching.put(bundle.getVersion(), bundle);
}
}
if (!matching.isEmpty()) {
Bundle bundle = matching.lastEntry().getValue();
deployment.toUpdate.put(bundle, resource);
deployment.toDelete.remove(bundle);
result.resToBnd.put(resource, bundle);
} else {
deployment.toInstall.add(resource);
}
}
Collections.sort(deployment.toInstall, new ResourceComparator());
// Add this region if there is something to do
if (!deployment.toDelete.isEmpty() || !deployment.toUpdate.isEmpty() || !deployment.toInstall.isEmpty()) {
result.regions.put(region, deployment);
}
}
return result;
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class RequirementSort method collectDependencies.
@SuppressWarnings("unchecked")
private static <T extends Resource> Set<T> collectDependencies(T resource, CapabilitySet capSet) {
Set<T> result = new LinkedHashSet<>();
for (Requirement requirement : resource.getRequirements(null)) {
String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
SimpleFilter sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
for (Capability cap : capSet.match(sf, true)) {
result.add((T) cap.getResource());
}
}
return result;
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class DeployToProfileMojo method uploadRequirements.
protected DeployResults uploadRequirements(J4pClient client, ProjectRequirements requirements) throws Exception {
String json = DtoHelper.getMapper().writeValueAsString(requirements);
ObjectName mbeanName = ProjectDeployerImpl.OBJECT_NAME;
getLog().info("Updating " + (requirements.isAbstractProfile() ? "abstract " : "") + "profile: " + requirements.getProfileId() + " with parent profile(s): " + requirements.getParentProfiles() + (requirements.isUseResolver() ? " using OSGi resolver" : "") + (requirements.isLocked() ? " locked" : ""));
getLog().info("About to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername());
getLog().debug("JSON: " + json);
try {
// Append bundles to existing profile bundles if we're not running the plugin at project root
Boolean appendBundles = !mavenSession.getExecutionRootDirectory().equalsIgnoreCase(project.getBasedir().toString());
J4pExecRequest request = new J4pExecRequest(mbeanName, "deployProjectJsonMergeOption(java.lang.String,boolean)", json, appendBundles);
J4pResponse<J4pExecRequest> response = client.execute(request, "POST");
Object value = response.getValue();
if (value == null) {
return null;
} else {
DeployResults answer = DtoHelper.getMapper().reader(DeployResults.class).readValue(value.toString());
if (answer != null) {
String profileUrl = answer.getProfileUrl();
if (profileUrl != null) {
getLog().info("");
getLog().info("Profile page: " + profileUrl);
getLog().info("");
} else {
getLog().info("Result: " + answer);
}
} else {
getLog().info("Result: " + value);
}
return answer;
}
} catch (J4pRemoteException e) {
if (e.getMessage().contains(".InstanceNotFoundException")) {
throw new MojoExecutionException("Could not find the mbean " + mbeanName + " in the JVM for " + jolokiaUrl + ". Are you sure this JVM is running the Fabric8 console?");
} else {
getLog().error("Failed to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername() + ". Error: " + e.getErrorType());
getLog().error("Stack: " + e.getRemoteStackTrace());
throw e;
}
}
}
Aggregations