use of io.fabric8.openshift.api.model.Project in project fabric8-maven-plugin by fabric8io.
the class WatchMojo method customizeConfig.
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
try {
Fabric8ServiceHub serviceHub = getFabric8ServiceHub();
GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:watch").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).artifactResolver(serviceHub.getArtifactResolverService()).build();
return GeneratorManager.generate(configs, ctx, false);
} catch (MojoExecutionException e) {
throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
}
}
use of io.fabric8.openshift.api.model.Project in project vertx-openshift-it by cescoffier.
the class OpenShiftTestAssistant method deployApplication.
public String deployApplication() throws IOException {
applicationName = System.getProperty("app.name");
List<? extends HasMetadata> entities = deploy("application", new File("target/classes/META-INF/fabric8/openshift.yml"));
Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
if (applicationName == null && first.isPresent()) {
applicationName = first.get();
}
Route route = client.adapt(OpenShiftClient.class).routes().inNamespace(project).withName(applicationName).get();
assertThat(route).isNotNull();
RestAssured.baseURI = "http://" + Objects.requireNonNull(route).getSpec().getHost();
System.out.println("Route url: " + RestAssured.baseURI);
return applicationName;
}
use of io.fabric8.openshift.api.model.Project in project fabric8 by fabric8io.
the class Configuration method findNamespaceForEnvironment.
/**
* Resolves a logical environment name for a project, such as <code>Testing</code> to the physical projcect/team specific
* namespace value.
*
* It tries to find a fabric8.yml file in this folder or a parent folder and loads it and tries to use it to find the
* namespace for the given environment or uses environment variables to resolve the environment name -> physical namespace
* @return the namespace
*/
private static String findNamespaceForEnvironment(String environment, Map<String, String> map, KubernetesClient kubernetesClient, String developNamespace, boolean failOnMissingEnvironmentNamespace) {
String namespace = null;
if (!Strings.isNullOrBlank(environment)) {
namespace = Environments.namespaceForEnvironment(kubernetesClient, environment, developNamespace);
if (Strings.isNotBlank(namespace)) {
return namespace;
}
String basedir = System.getProperty("basedir", ".");
File folder = new File(basedir);
ProjectConfig projectConfig = ProjectConfigs.findFromFolder(folder);
if (projectConfig != null) {
LinkedHashMap<String, String> environments = projectConfig.getEnvironments();
if (environments != null) {
namespace = environments.get(environment);
}
}
String key = environment.toLowerCase() + ".namespace";
if (Strings.isNullOrBlank(namespace)) {
// lets try find an environment variable or system property
namespace = getStringProperty(key, map, null);
}
if (Strings.isNullOrBlank(namespace)) {
if (failOnMissingEnvironmentNamespace) {
throw new IllegalStateException("A fabric8 environment '" + environment + "' has been specified, but no matching namespace was found in the fabric8.yml file or '" + key + "' system property");
} else {
return developNamespace;
}
}
}
return namespace;
}
use of io.fabric8.openshift.api.model.Project in project fabric8 by fabric8io.
the class Controller method applyProjectRequest.
/**
* Returns true if the ProjectRequest is created
*/
public boolean applyProjectRequest(ProjectRequest entity) {
String namespace = getOrCreateMetadata(entity).getName();
LOG.info("Using project: " + namespace);
String name = getName(entity);
Objects.notNull(name, "No name for " + entity);
OpenShiftClient openshiftClient = getOpenShiftClientOrNull();
if (openshiftClient == null || !openshiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.PROJECT)) {
LOG.warn("Cannot check for Project " + namespace + " as not running against OpenShift!");
return false;
}
boolean exists = checkNamespace(name);
// We may want to be more fine-grained on the phase of the project
if (!exists) {
try {
Object answer = openshiftClient.projectrequests().create(entity);
logGeneratedEntity("Created ProjectRequest: ", namespace, entity, answer);
return true;
} catch (Exception e) {
onApplyError("Failed to create ProjectRequest: " + name + " due " + e.getMessage(), e);
}
}
return false;
}
use of io.fabric8.openshift.api.model.Project in project fabric8 by fabric8io.
the class Controller method applyNamespace.
public void applyNamespace(String namespaceName, Map<String, String> labels) {
if (Strings.isNullOrBlank(namespaceName)) {
return;
}
OpenShiftClient openshiftClient = getOpenShiftClientOrNull();
if (openshiftClient != null && openshiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.PROJECT)) {
ProjectRequest entity = new ProjectRequest();
ObjectMeta metadata = getOrCreateMetadata(entity);
metadata.setName(namespaceName);
String namespace = kubernetesClient.getNamespace();
if (Strings.isNotBlank(namespace)) {
Map<String, String> entityLabels = getOrCreateLabels(entity);
if (labels != null) {
entityLabels.putAll(labels);
} else {
// lets associate this new namespace with the project that it was created from
entityLabels.put("project", namespace);
}
}
applyProjectRequest(entity);
} else {
Namespace entity = new Namespace();
ObjectMeta metadata = getOrCreateMetadata(entity);
metadata.setName(namespaceName);
String namespace = kubernetesClient.getNamespace();
if (Strings.isNotBlank(namespace)) {
Map<String, String> entityLabels = getOrCreateLabels(entity);
if (labels != null) {
entityLabels.putAll(labels);
} else {
// lets associate this new namespace with the project that it was created from
entityLabels.put("project", namespace);
}
}
applyNamespace(entity);
}
}
Aggregations