use of io.fabric8.kubernetes.model.annotation.Version 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.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class FabricMBeanFacadeTest method testVersionsWithOnlyIDs.
@Test
public void testVersionsWithOnlyIDs() {
// this can only be run if you have a fabric running...
Assume.assumeTrue(Boolean.valueOf(System.getProperty("hasFabric")));
FabricMBean facade = getFabricMBean();
String json = facade.versions(Helpers.toList("id"));
try {
Collection<VersionDTO> versions = Helpers.getObjectMapper().readValue(json, TypeFactory.defaultInstance().constructParametricType(Collection.class, VersionDTO.class));
Assume.assumeNotNull(versions);
for (Object version : versions) {
System.out.println(version);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class AbstractChildContainerCreateAction method preCreateContainer.
/**
* Pre validates input before creating the container(s)
*
* @param name the name of the container to create
* @throws IllegalArgumentException is thrown if input is invalid
*/
protected void preCreateContainer(String name) throws IllegalArgumentException {
FabricValidations.validateContainerName(name);
if (clusterService.getEnsembleContainers().isEmpty()) {
return;
}
if (FabricCommand.doesContainerExist(fabricService, name)) {
throw new IllegalArgumentException("A container with name " + name + " already exists.");
}
// get the profiles for the given version
Version ver = version != null ? profileService.getRequiredVersion(version) : fabricService.getRequiredDefaultVersion();
List<Profile> profiles = ver.getProfiles();
// validate profiles exists before creating a new container
Set<String> names = getProfileNames();
for (String profile : names) {
Profile prof = getProfile(profiles, profile, ver);
if (prof == null) {
throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " does not exist.");
}
if (prof.isAbstract()) {
throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " is abstract and can not be associated to containers.");
}
}
if (fabricService.getZookeeperUrl() == null) {
throw new IllegalArgumentException("should start a zookeeper ensemble first.");
}
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class AbstractContainerCreateAction method preCreateContainer.
/**
* Pre validates input before creating the container(s)
*
* @param name the name of the container to create
* @throws IllegalArgumentException is thrown if input is invalid
*/
protected void preCreateContainer(String name) throws IllegalArgumentException {
FabricValidations.validateContainerName(name);
if (!isEnsembleServer) {
if (clusterService.getEnsembleContainers().isEmpty()) {
if (!isEnsembleServer) {
throw new IllegalStateException("The use of the --ensemble-server option is mandatory when creating an initial container");
}
return;
}
if (FabricCommand.doesContainerExist(fabricService, name)) {
throw new IllegalArgumentException("A container with name " + name + " already exists.");
}
// get the profiles for the given version
Version ver = version != null ? profileService.getRequiredVersion(version) : fabricService.getRequiredDefaultVersion();
List<Profile> profiles = ver.getProfiles();
// validate profiles exists before creating a new container
Set<String> names = getProfileNames();
for (String profile : names) {
Profile prof = getProfile(profiles, profile, ver);
if (prof == null) {
throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " does not exist.");
}
if (prof.isAbstract()) {
throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " is abstract and can not be associated to containers.");
}
}
}
if (!isEnsembleServer && fabricService.getZookeeperUrl() == null) {
throw new IllegalArgumentException("Either start a zookeeper ensemble or use --ensemble-server.");
}
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class ProjectDeployerImpl method deployProject.
@Override
public DeployResults deployProject(ProjectRequirements requirements, boolean merge) throws Exception {
Version version = getOrCreateVersion(requirements);
// validate that all the parent profiles exists
for (String parent : requirements.getParentProfiles()) {
if (!version.hasProfile(parent)) {
throw new IllegalArgumentException("Parent profile " + parent + " does not exists in version " + version.getId());
}
}
Profile profile = getOrCreateProfile(version, requirements);
boolean isAbstract = requirements.isAbstractProfile();
ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
builder.addAttribute(Profile.ABSTRACT, "" + isAbstract);
ProjectRequirements oldRequirements = writeRequirementsJson(requirements, profile, builder);
updateProfileConfiguration(version, profile, requirements, oldRequirements, builder, merge);
return resolveProfileDeployments(requirements, fabricService.get(), profile, builder, merge);
}
Aggregations