use of io.fabric8.openshift.api.model.Parameter in project fabric8 by fabric8io.
the class Templates method combineParameters.
protected static void combineParameters(List<Parameter> parameters, List<Parameter> otherParameters) {
if (otherParameters != null && otherParameters.size() > 0) {
Map<String, Parameter> map = new HashMap<>();
for (Parameter parameter : parameters) {
map.put(parameter.getName(), parameter);
}
for (Parameter otherParameter : otherParameters) {
String name = otherParameter.getName();
Parameter original = map.get(name);
if (original == null) {
parameters.add(otherParameter);
} else {
if (Strings.isNotBlank(original.getValue())) {
original.setValue(otherParameter.getValue());
}
}
}
}
}
use of io.fabric8.openshift.api.model.Parameter in project fabric8 by fabric8io.
the class Templates method processTemplatesLocally.
/**
* Lets locally process the templates so that we can process templates on any kubernetes environment
*/
public static KubernetesList processTemplatesLocally(Template entity, boolean failOnMissingParameterValue) throws IOException {
List<HasMetadata> objects = null;
if (entity != null) {
objects = entity.getObjects();
if (objects == null || objects.isEmpty()) {
return null;
}
}
List<Parameter> parameters = entity != null ? entity.getParameters() : null;
if (parameters != null && !parameters.isEmpty()) {
String json = "{\"kind\": \"List\", \"apiVersion\": \"" + KubernetesHelper.defaultApiVersion + "\",\n" + " \"items\": " + KubernetesHelper.toJson(objects) + " }";
// lets make a few passes in case there's expressions in values
for (int i = 0; i < 5; i++) {
for (Parameter parameter : parameters) {
String name = parameter.getName();
String regex = "${" + name + "}";
String value = parameter.getValue();
// TODO generate random strings for passwords etc!
if (Strings.isNullOrBlank(value)) {
if (failOnMissingParameterValue) {
throw new IllegalArgumentException("No value available for parameter name: " + name);
} else {
value = "";
}
}
json = Strings.replaceAllWithoutRegex(json, regex, value);
}
}
return OBJECT_MAPPER.readerFor(KubernetesList.class).readValue(json);
} else {
KubernetesList answer = new KubernetesList();
answer.setItems(objects);
return answer;
}
}
use of io.fabric8.openshift.api.model.Parameter in project fabric8 by fabric8io.
the class KubernetesHelper method summaryText.
/**
* Returns a short summary text message for the given kubernetes resource
*/
public static String summaryText(Template entity) {
StringBuilder buffer = new StringBuilder();
List<Parameter> parameters = entity.getParameters();
if (parameters != null) {
for (Parameter parameter : parameters) {
String name = parameter.getName();
appendText(buffer, name);
}
}
return "parameters: " + buffer;
}
use of io.fabric8.openshift.api.model.Parameter in project fabric8 by jboss-fuse.
the class Main method main.
public static void main(String[] args) throws Exception {
File patch;
File base;
if (args.length < 1) {
help();
return;
}
patch = new File(args[0]);
if (!patch.isFile()) {
System.err.println("Invalid patch file");
return;
}
if (args.length > 1) {
base = new File(args[1]);
} else {
base = new File(System.getProperty("karaf.base"));
}
if (!new File(base, "system").isDirectory() || !new File(base, "etc").isDirectory()) {
System.err.println("Invalid karaf-base parameter");
return;
}
new Offline(base).apply(patch);
}
use of io.fabric8.openshift.api.model.Parameter in project fabric8 by fabric8io.
the class FactoryMethodProducer method produce.
@Override
public T produce(CreationalContext<T> ctx) {
List<Object> arguments = new ArrayList<>();
for (AnnotatedParameter<X> parameter : factoryMethod.getParameters()) {
Type type = parameter.getBaseType();
ServiceName parameterServiceName = parameter.getAnnotation(ServiceName.class);
Protocol parameterProtocol = parameter.getAnnotation(Protocol.class);
PortName parameterPortName = parameter.getAnnotation(PortName.class);
Path parameterPath = parameter.getAnnotation(Path.class);
Endpoint paramEndpoint = parameter.getAnnotation(Endpoint.class);
External paramExternal = parameter.getAnnotation(External.class);
Configuration configuration = parameter.getAnnotation(Configuration.class);
// A point without @ServiceName is invalid.
// Even if method defines @ServiceName, the annotation on the injection point takes precedence
String serviceName = pointName;
String serviceProtocol = or(pointProtocol, parameterProtocol != null ? parameterProtocol.value() : null);
String servicePort = or(pointPort, parameterPortName != null ? parameterPortName.value() : null);
String servicePath = or(pointPath, parameterPath != null ? parameterPath.value() : null);
Boolean serviceEndpoint = paramEndpoint != null ? paramEndpoint.value() : false;
Boolean serviceExternal = paramExternal != null ? paramExternal.value() : false;
// If the @ServiceName exists on the current String property
if (parameterServiceName != null && String.class.equals(type)) {
try {
String serviceUrl = getServiceUrl(serviceName, serviceProtocol, servicePort, servicePath, serviceEndpoint, serviceExternal, ctx);
arguments.add(serviceUrl);
} catch (Throwable t) {
throw new RuntimeException(String.format(SERVICE_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
}
} else // If the @ServiceName exists on the current List property
if (parameterServiceName != null && List.class.equals(Types.asClass(type))) {
try {
List<String> endpointList = getEndpointList(serviceName, serviceProtocol, servicePort, servicePath, serviceExternal, ctx);
arguments.add(endpointList);
} catch (Throwable t) {
throw new RuntimeException(String.format(SERVICE_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
}
} else // If the @ServiceName exists on the current List property
if (parameterServiceName != null && Set.class.equals(Types.asClass(type))) {
try {
List<String> endpointList = getEndpointList(serviceName, serviceProtocol, servicePort, servicePath, serviceExternal, ctx);
arguments.add(new HashSet<>(endpointList));
} catch (Throwable t) {
throw new RuntimeException(String.format(SERVICE_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
}
} else // If the @ServiceName exists on the current property which is a non-String
if (parameterServiceName != null && !String.class.equals(type)) {
try {
Object serviceBean = getServiceBean(serviceName, serviceProtocol, servicePort, servicePath, serviceEndpoint, serviceExternal, type, ctx);
arguments.add(serviceBean);
} catch (Throwable t) {
throw new RuntimeException(String.format(BEAN_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), type, serviceName), t);
}
} else // If the current parameter is annotated with @Configuration
if (configuration != null) {
try {
Object config = getConfiguration(serviceName, (Class<Object>) type, ctx);
arguments.add(config);
} catch (Throwable t) {
throw new RuntimeException(String.format(CONF_LOOKUP_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), serviceName), t);
}
} else {
try {
Object other = BeanProvider.getContextualReference(Types.asClass(type), true);
arguments.add(other);
} catch (Throwable t) {
throw new RuntimeException(String.format(PARAMETER_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), parameter.getPosition()), t);
}
}
}
try {
return (T) factoryMethod.getJavaMember().invoke(bean.create(ctx), arguments.toArray());
} catch (Throwable t) {
throw new RuntimeException(String.format(INVOCATION_ERROR_FORMAT, factoryMethod.getJavaMember().getName(), factoryMethod.getJavaMember().getDeclaringClass().getName(), arguments), t);
}
}
Aggregations