use of io.fabric8.openshift.api.model.User in project fabric8 by fabric8io.
the class ShowConfig method main.
public static void main(String... args) {
try {
System.out.println("Current username: " + currentUserName());
Config config = Configs.parseConfigs();
if (config == null) {
System.out.println("No Config loaded!");
} else {
Context context = Configs.getCurrentContext(config);
if (context != null) {
System.out.println("context: " + config.getCurrentContext());
System.out.println("cluster: " + context.getCluster());
System.out.println("user: " + context.getUser());
System.out.println("namespace: " + context.getNamespace());
} else {
System.out.println("No current context!");
}
}
} catch (Exception e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
use of io.fabric8.openshift.api.model.User in project syndesis-qe by syndesisio.
the class TestConfiguration method defaultValues.
private Properties defaultValues() {
final Properties defaultProps = new Properties();
defaultProps.setProperty(OPENSHIFT_URL, "");
defaultProps.setProperty(OPENSHIFT_TOKEN, "");
defaultProps.setProperty(SYNDESIS_LOCAL_REST_URL, "http://localhost:8080");
defaultProps.setProperty(SYNDESIS_CREDENTIALS_FILE, "../credentials.json");
defaultProps.setProperty(SYNDESIS_VERSIONS_FILE, "src/test/resources/dependencyVersions.properties");
defaultProps.setProperty(SYNDESIS_UI_BROWSER, "chrome");
defaultProps.setProperty(OPENSHIFT_NAMESPACE_CLEANUP, "false");
// to keep backward compatibility
if (properties.getProperty(SYNDESIS_URL_SUFFIX) != null && properties.getProperty(OPENSHIFT_ROUTE_SUFFIX) == null) {
defaultProps.setProperty(OPENSHIFT_ROUTE_SUFFIX, properties.getProperty(SYNDESIS_URL_SUFFIX));
}
String syndesisVersion;
if (System.getProperty(SYNDESIS_INSTALL_VERSION) != null) {
syndesisVersion = System.getProperty(SYNDESIS_INSTALL_VERSION);
} else {
syndesisVersion = "master";
// only use defined system property if it doesnt end with SNAPSHOT and it is not prod build
if (!properties.getProperty(SYNDESIS_VERSION).endsWith("SNAPSHOT") && !properties.getProperty(SYNDESIS_VERSION).contains("redhat")) {
syndesisVersion = System.getProperty(SYNDESIS_VERSION);
}
}
if (properties.getProperty(SYNDESIS_PUBLIC_OAUTH_PROXY_URL) == null) {
defaultProps.setProperty(SYNDESIS_PUBLIC_OAUTH_PROXY_URL, String.format("https://raw.githubusercontent.com/syndesisio/syndesis/%s/install/support/syndesis-public-oauth-proxy.yml", syndesisVersion));
}
defaultProps.setProperty(SYNDESIS_CRD_URL, getClass().getClassLoader().getResource("syndesis-crd.yaml").toString());
String operatorVersion;
if (this.properties.getProperty(SYNDESIS_INSTALL_VERSION) != null) {
operatorVersion = this.properties.getProperty(SYNDESIS_INSTALL_VERSION);
} else {
operatorVersion = "latest";
}
if (properties.getProperty(SYNDESIS_DOCKER_REGISTRY) == null) {
defaultProps.setProperty(SYNDESIS_DOCKER_REGISTRY, "quay.io");
defaultProps.setProperty(SYNDESIS_OPERATOR_IMAGE, String.format("%s/syndesis/syndesis-operator:%s", defaultProps.get(SYNDESIS_DOCKER_REGISTRY), operatorVersion));
} else {
defaultProps.setProperty(SYNDESIS_OPERATOR_IMAGE, String.format("%s/syndesis/syndesis-operator:%s", properties.get(SYNDESIS_DOCKER_REGISTRY), operatorVersion));
}
if (properties.getProperty(SYNDESIS_CR_URL) == null) {
defaultProps.setProperty(SYNDESIS_CR_URL, "https://raw.githubusercontent.com/syndesisio/fuse-online-install/master/default-cr.yml");
}
defaultProps.setProperty(SYNDESIS_CUSTOM_RESOURCE_PLURAL, "syndesises");
// Make the user "admin" anyway, as that user is used in all k8s client invocations by default
if (properties.getProperty(SYNDESIS_SINGLE_USER) != null) {
// need to be in the main properties because it will be used for xtf settings
properties.setProperty(SYNDESIS_ADMIN_USERNAME, properties.getProperty(SYNDESIS_UI_USERNAME));
}
if (properties.getProperty(SYNDESIS_SINGLE_USER) != null) {
// need to be in the main properties because it will be used for xtf settings
properties.setProperty(SYNDESIS_ADMIN_PASSWORD, properties.getProperty(SYNDESIS_UI_PASSWORD));
}
if (!Boolean.parseBoolean(String.valueOf(properties.get(SYNDESIS_ENVIRONMENT_DELOREAN)))) {
// Copy syndesis properties to their xtf counterparts - used by binary oc client
System.setProperty("xtf.openshift.url", properties.getProperty(OPENSHIFT_URL));
System.setProperty("xtf.openshift.master.username", properties.getProperty(SYNDESIS_ADMIN_USERNAME));
System.setProperty("xtf.openshift.master.password", properties.getProperty(SYNDESIS_ADMIN_PASSWORD));
} else {
// get openshift url from the default client which use KUBECONFIG
DefaultKubernetesClient defaultKubernetesClient = new DefaultKubernetesClient();
defaultProps.setProperty(OPENSHIFT_URL, defaultKubernetesClient.getMasterUrl().toString());
System.setProperty("xtf.openshift.url", defaultKubernetesClient.getMasterUrl().toString());
log.info("Kubernetes master URL: " + defaultKubernetesClient.getMasterUrl().toString());
defaultKubernetesClient.close();
}
System.setProperty("xtf.openshift.namespace", properties.getProperty(OPENSHIFT_NAMESPACE));
// Set oc version - this version of the client will be used as the binary client
System.setProperty("xtf.openshift.version", "4.3");
// Set jackson properties for productized build
System.setProperty("jackson.deserialization.whitelist.packages", "io.syndesis.common.model,io.atlasmap");
/*
* Resteasy 4.4 uses 2.10 jackson that has this security feature due to CVEs and the only option is to use system properties for that
* Needed for atlasmap to be able to deserialize inspection response
*/
System.setProperty("resteasy.jackson.deserialization.whitelist.allowIfBaseType.prefix", "*");
System.setProperty("resteasy.jackson.deserialization.whitelist.allowIfSubType.prefix", "*");
if (properties.getProperty(SYNDESIS_RUNTIME) == null) {
defaultProps.setProperty(SYNDESIS_RUNTIME, "springboot");
}
if (properties.getProperty(SYNDESIS_PULL_SECRET_NAME) == null) {
defaultProps.setProperty(SYNDESIS_PULL_SECRET_NAME, "syndesis-pull-secret");
}
defaultProps.setProperty(STATE_CHECK_INTERVAL, "" + (System.getenv("WORKSPACE") != null ? 150 : 90));
if (properties.getProperty(SNOOP_SELECTORS) == null) {
defaultProps.setProperty(SNOOP_SELECTORS, "false");
}
if (properties.getProperty(CAMEL_K_VERSION) == null) {
defaultProps.setProperty(CAMEL_K_VERSION, "0.3.4");
}
if (properties.getProperty(JAEGER_VERSION) == null) {
defaultProps.setProperty(JAEGER_VERSION, "1.20.0");
}
if (properties.getProperty(SYNDESIS_APPEND_REPOSITORY) == null) {
defaultProps.setProperty(SYNDESIS_APPEND_REPOSITORY, "true");
}
if (properties.getProperty(KEYCLOAK_NAMESPACE) == null) {
defaultProps.setProperty(KEYCLOAK_NAMESPACE, "keycloak");
}
if (properties.getProperty(KEYCLOAK_SYNDESIS_REALM) == null) {
defaultProps.setProperty(KEYCLOAK_SYNDESIS_REALM, "syndesis");
}
if (properties.getProperty(KEYCLOAK_IDP_NAME) == null) {
defaultProps.setProperty(KEYCLOAK_IDP_NAME, "OpenID_keycloak");
}
return defaultProps;
}
use of io.fabric8.openshift.api.model.User in project syndesis-qe by syndesisio.
the class MongoDb36 method addAccount.
public void addAccount() {
Account mongodbAccount = new Account();
mongodbAccount.setService("mongodb36");
Map<String, String> accountParameters = new HashMap<>();
accountParameters.put("host", APP_NAME);
accountParameters.put("user", MONGODB_USER);
accountParameters.put("password", MONGODB_PASSWORD);
accountParameters.put("database", MONGODB_DATABASE);
// this does not work for now
// accountParameters.put("admindb", MONGODB_DATABASE);
accountParameters.put("url", MONGDB_URL);
mongodbAccount.setProperties(accountParameters);
AccountsDirectory.getInstance().addAccount(Account.Name.MONGODB36.getId(), mongodbAccount);
}
use of io.fabric8.openshift.api.model.User in project syndesis-qe by syndesisio.
the class MySQL method deploy.
@Override
public void deploy() {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName("mysql-cmd").withContainerPort(3306).withProtocol("TCP").build());
List<EnvVar> templateParams = new ArrayList<>();
templateParams.add(new EnvVar("MYSQL_USER", DB_USER, null));
templateParams.add(new EnvVar("MYSQL_PASSWORD", DB_PASSWORD, null));
templateParams.add(new EnvVar("MYSQL_DATABASE", DB_SCHEMA, null));
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("quay.io/syndesis_qe/mysql-57-centos7").addAllToPorts(ports).addAllToEnv(templateParams).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("mysql-cmd").withPort(3306).withTargetPort(new IntOrString(3306)).build());
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
try {
OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
Thread.sleep(20 * 1000);
} catch (InterruptedException | TimeoutException e) {
log.error("Wait for {} deployment failed ", APP_NAME, e);
}
Account mysqlAccount = new Account();
mysqlAccount.setService("mysql");
Map<String, String> accountParameters = new HashMap<>();
accountParameters.put("url", DB_URL);
accountParameters.put("user", DB_USER);
accountParameters.put("password", DB_PASSWORD);
accountParameters.put("schema", DB_SCHEMA);
mysqlAccount.setProperties(accountParameters);
AccountsDirectory.getInstance().addAccount("mysql", mysqlAccount);
}
use of io.fabric8.openshift.api.model.User in project syndesis-qe by syndesisio.
the class SyndesisDB method deploy.
@Override
public void deploy() {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName("psql-cmd").withContainerPort(5432).withProtocol("TCP").build());
List<EnvVar> templateParams = new ArrayList<>();
templateParams.add(new EnvVar("POSTGRESQL_USER", DB_ROOT_USER, null));
templateParams.add(new EnvVar("POSTGRESQL_PASSWORD", DB_PASSWORD, null));
// sample DB schema is created by post start script, this DB is not important
templateParams.add(new EnvVar("POSTGRESQL_DATABASE", "whatever", null));
templateParams.add(new EnvVar("POSTGRESQL_SAMPLEDB_PASSWORD", DB_PASSWORD, null));
// config map with the post start script
if (OpenShiftUtils.getInstance().getConfigMap("syndesis-sampledb-config") == null) {
try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-sampledb-config.yml")) {
ConfigMap cm = OpenShiftUtils.getInstance().configMaps().load(is).get();
OpenShiftUtils.getInstance().createConfigMap(cm);
} catch (IOException ex) {
throw new IllegalArgumentException("Unable to read config map ", ex);
}
}
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("quay.io/syndesis_qe/postgresql-10-centos7:latest").addAllToPorts(ports).addAllToEnv(templateParams).editOrNewLifecycle().editOrNewPostStart().editOrNewExec().addNewCommand("/bin/sh").addNewCommand("-c").addNewCommand("/var/lib/pgsql/sampledb/postStart.sh").endExec().endPostStart().endLifecycle().addNewVolumeMount().withNewMountPath("/var/lib/pgsql/sampledb").withName("syndesis-sampledb-config").endVolumeMount().endContainer().addNewVolume().editOrNewConfigMap().withName("syndesis-sampledb-config").withDefaultMode(511).endConfigMap().withName("syndesis-sampledb-config").endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("psql-cmd").withPort(5432).withTargetPort(new IntOrString(5432)).build());
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
try {
OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
Thread.sleep(20 * 1000);
} catch (InterruptedException | TimeoutException e) {
log.error("Wait for {} deployment failed ", APP_NAME, e);
}
Account syndesisDbAccount = new Account();
syndesisDbAccount.setService("SyndesisDB");
Map<String, String> accountParameters = new HashMap<>();
accountParameters.put("url", DB_URL);
accountParameters.put("user", DB_SAMPLE_DB_USER);
accountParameters.put("password", DB_PASSWORD);
accountParameters.put("schema", DB_SCHEMA);
syndesisDbAccount.setProperties(accountParameters);
AccountsDirectory.getInstance().addAccount(Account.Name.SYNDESIS_DB.getId(), syndesisDbAccount);
Connection defaultPostgresDBConnection = connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_ORIGINAL);
// (When the test suite was killed before, the backup can exist and original connection was already changed, ignore in that case
if (connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_BACKUP) == null) {
connectionsEndpoint.create(defaultPostgresDBConnection.builder().name(DEFAULT_PSQL_CONNECTION_BACKUP).id("1000").build());
}
// config prop for new instance
Map<String, String> configuredProperties = new HashMap<>(defaultPostgresDBConnection.getConfiguredProperties());
configuredProperties.put("schema", DB_SCHEMA);
configuredProperties.put("password", DB_PASSWORD);
configuredProperties.put("user", DB_SAMPLE_DB_USER);
configuredProperties.put("url", DB_URL);
Connection build = defaultPostgresDBConnection.builder().configuredProperties(configuredProperties).build();
connectionsEndpoint.update(defaultPostgresDBConnection.getId().get(), build);
}
Aggregations