use of io.fabric8.agent.service.State in project che by eclipse.
the class OpenShiftConnector method createContainer.
/**
* @param createContainerParams
* @return
* @throws IOException
*/
@Override
public ContainerCreated createContainer(CreateContainerParams createContainerParams) throws IOException {
String containerName = KubernetesStringUtils.convertToContainerName(createContainerParams.getContainerName());
String workspaceID = getCheWorkspaceId(createContainerParams);
// Generate workspaceID if CHE_WORKSPACE_ID env var does not exist
workspaceID = workspaceID.isEmpty() ? KubernetesStringUtils.generateWorkspaceID() : workspaceID;
// imageForDocker is the docker version of the image repository. It's needed for other
// OpenShiftConnector API methods, but is not acceptable as an OpenShift name
String imageForDocker = createContainerParams.getContainerConfig().getImage();
// imageStreamTagName is imageForDocker converted into a form that can be used
// in OpenShift
String imageStreamTagName = KubernetesStringUtils.convertPullSpecToTagName(imageForDocker);
// imageStreamTagName is not enough to fill out a pull spec; it is only the tag, so we
// have to get the ImageStreamTag from the tag, and then get the full ImageStreamTag name
// from that tag. This works because the tags used in Che are unique.
ImageStreamTag imageStreamTag = getImageStreamTagFromRepo(imageStreamTagName);
String imageStreamTagPullSpec = imageStreamTag.getMetadata().getName();
// Next we need to get the address of the registry where the ImageStreamTag is stored
String imageStreamName = KubernetesStringUtils.getImageStreamNameFromPullSpec(imageStreamTagPullSpec);
ImageStream imageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
if (imageStream == null) {
throw new OpenShiftException("ImageStream not found");
}
String registryAddress = imageStream.getStatus().getDockerImageRepository().split("/")[0];
// The above needs to be combined to form a pull spec that will work when defining a container.
String dockerPullSpec = String.format("%s/%s/%s", registryAddress, openShiftCheProjectName, imageStreamTagPullSpec);
Set<String> containerExposedPorts = createContainerParams.getContainerConfig().getExposedPorts().keySet();
Set<String> imageExposedPorts = inspectImage(InspectImageParams.create(imageForDocker)).getConfig().getExposedPorts().keySet();
Set<String> exposedPorts = getExposedPorts(containerExposedPorts, imageExposedPorts);
boolean runContainerAsRoot = runContainerAsRoot(imageForDocker);
String[] envVariables = createContainerParams.getContainerConfig().getEnv();
String[] volumes = createContainerParams.getContainerConfig().getHostConfig().getBinds();
Map<String, String> additionalLabels = createContainerParams.getContainerConfig().getLabels();
String containerID;
try {
createOpenShiftService(workspaceID, exposedPorts, additionalLabels);
String deploymentName = createOpenShiftDeployment(workspaceID, dockerPullSpec, containerName, exposedPorts, envVariables, volumes, runContainerAsRoot);
containerID = waitAndRetrieveContainerID(deploymentName);
if (containerID == null) {
throw new OpenShiftException("Failed to get the ID of the container running in the OpenShift pod");
}
} catch (IOException e) {
// Make sure we clean up deployment and service in case of an error -- otherwise Che can end up
// in an inconsistent state.
LOG.info("Error while creating Pod, removing deployment");
String deploymentName = CHE_OPENSHIFT_RESOURCES_PREFIX + workspaceID;
cleanUpWorkspaceResources(deploymentName);
openShiftClient.resource(imageStreamTag).delete();
throw e;
}
return new ContainerCreated(containerID, null);
}
use of io.fabric8.agent.service.State in project fabric8 by jboss-fuse.
the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepositoryActingAsRemote.
@Test
public void snapshotIsAvailableInDefaultRepositoryActingAsRemote() throws IOException, InvalidMavenArtifactRequest {
File differentLocalRepository = initFileRepository("dlr");
File defaultRepository = initFileRepository("dr");
MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
servlet.start();
mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
// Here's expected state of repository where SNAPSHOT was `mvn deploy`ed
assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
Metadata metadata = readMetadata(file);
boolean checked = false;
assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(false));
for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
if ("jar".equals(snapshotVersion.getExtension())) {
assertThat(snapshotVersion.getVersion(), is("0.1.0-20170101.100000-1"));
checked = true;
}
}
assertTrue("We should find snapshot metadata", checked);
// download artifact using version from metadata
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-20170101.100000-1/universalis-api-0.1.0-20170101.100000-1.jar");
assertThat(FileUtils.readFileToString(file), equalTo("a"));
mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
metadata = readMetadata(file);
assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.110000-2"));
}
use of io.fabric8.agent.service.State in project fabric8 by jboss-fuse.
the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepository.
@Test
public void snapshotIsAvailableInDefaultRepository() throws IOException, InvalidMavenArtifactRequest {
File defaultRepository = initFileRepository("dr");
MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
servlet.start();
mvnInstall(defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
// Here's expected state of repository where SNAPSHOT was `mvn install`ed
assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
Metadata metadata = readMetadata(file);
boolean checked = false;
assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(true));
for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
if ("jar".equals(snapshotVersion.getExtension())) {
assertThat(snapshotVersion.getVersion(), is("0.1.0-SNAPSHOT"));
checked = true;
}
}
assertTrue("We should find snapshot metadata", checked);
// if metadata says it's "0.1.0-SNAPSHOT", we should have no problem downloading this artifact without
// version transformation
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-SNAPSHOT.jar");
assertThat(FileUtils.readFileToString(file), equalTo("a"));
mvnInstall(defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-SNAPSHOT.jar");
assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", FileUtils.readFileToString(file), equalTo("b"));
}
use of io.fabric8.agent.service.State in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method updateMasterUrl.
private void updateMasterUrl(Group<GitNode> group) {
try {
if (group.isMaster()) {
LOGGER.debug("Git repo is the master");
if (!isMaster.getAndSet(true)) {
registerServlet(dataPath, realm, roles);
}
} else {
LOGGER.debug("Git repo is not the master");
if (isMaster.getAndSet(false)) {
unregisterServlet();
}
}
GitNode state = createState();
group.update(state);
String url = state.getUrl();
gitRemoteUrl.set(ZooKeeperUtils.getSubstitutedData(curator.get(), url));
} catch (Exception e) {
LOGGER.debug("Failed to update master git server url.", e);
}
}
use of io.fabric8.agent.service.State in project fabric8 by jboss-fuse.
the class Agent method loadResources.
//
// State support
//
public static Callable<Map<String, Resource>> loadResources(DownloadManager manager, Map<String, Map<VersionRange, Map<String, String>>> metadata, Set<String> uris) throws MultiException, InterruptedException, MalformedURLException {
final Map<String, Resource> resources = new HashMap<>();
final Downloader downloader = manager.createDownloader();
final MetadataBuilder builder = new MetadataBuilder(metadata);
final DownloadCallback callback = new DownloadCallback() {
@Override
public void downloaded(StreamProvider provider) throws Exception {
String uri = provider.getUrl();
Map<String, String> headers = builder.getMetadata(uri, provider.getFile());
Resource resource = ResourceBuilder.build(uri, headers);
synchronized (resources) {
resources.put(uri, resource);
}
}
};
for (String uri : uris) {
downloader.download(uri, callback);
}
return new Callable<Map<String, Resource>>() {
@Override
public Map<String, Resource> call() throws Exception {
downloader.await();
return resources;
}
};
}
Aggregations