use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.
the class SshContainerProvider method create.
/**
* Creates an {@link io.fabric8.api.Container} with the given name pointing to the specified zooKeeperUrl.
*/
public CreateSshContainerMetadata create(CreateSshContainerOptions options, CreationStateListener listener) {
try {
String path = options.getPath();
String host = options.getHost();
String ip = InetAddress.getByName(host).getHostAddress();
if (host == null) {
throw new IllegalArgumentException("Host name not specified.");
}
int port = options.getPort();
if (port == -1) {
port = 22;
}
String containerName = options.getName();
CreateSshContainerMetadata metadata = new CreateSshContainerMetadata();
metadata.setCreateOptions(options);
metadata.setContainerName(containerName);
String script = buildInstallAndStartScript(containerName, options);
LOGGER.debug("Running script on host {}:\n{}", host, script);
Session session = null;
try {
session = createSession(options);
if (options.doUploadDistribution()) {
uploadTo(session, options.getProxyUri().resolve("io/fabric8/fabric8-karaf/" + FabricConstants.FABRIC_VERSION + "/fabric8-karaf-" + FabricConstants.FABRIC_VERSION + ".zip").toURL(), "/tmp/fabric8-karaf-" + FabricConstants.FABRIC_VERSION + ".zip");
}
runScriptOnHost(session, script);
} catch (Throwable ex) {
metadata.setFailure(ex);
throw new FabricException(ex);
} finally {
if (session != null) {
session.disconnect();
}
}
return metadata;
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
}
use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.
the class BootstrapConfiguration method configureInternal.
void configureInternal(Map<String, ?> conf) throws Exception {
configuration = configurer.configure(conf, this);
if (Strings.isNullOrBlank(runtimeId)) {
throw new IllegalArgumentException("Runtime id must not be null or empty.");
}
if (Strings.isNullOrBlank(localResolver)) {
localResolver = globalResolver;
}
String decodedZookeeperPassword = null;
Properties userProps = new Properties();
try {
userProps.load(new File(confDir, "users.properties"));
} catch (IOException e) {
LOGGER.warn("Failed to load users from etc/users.properties. No users will be imported.", e);
}
if (Strings.isNotBlank(zookeeperPassword)) {
decodedZookeeperPassword = PasswordEncoder.decode(zookeeperPassword);
} else if (userProps.containsKey(DEFAULT_ADMIN_USER)) {
String passwordAndRole = userProps.getProperty(DEFAULT_ADMIN_USER).trim();
decodedZookeeperPassword = passwordAndRole.substring(0, passwordAndRole.indexOf(ROLE_DELIMITER));
} else {
decodedZookeeperPassword = PasswordEncoder.encode(CreateEnsembleOptions.generatePassword());
}
// do not trigger io.fabric8.zookeeper update if restart is pending (fabric:join)
if (!Boolean.getBoolean("karaf.restart") && zookeeperUrl != null && zookeeperPassword != null) {
Configuration zkConfugiration = configAdmin.get().getConfiguration(Constants.ZOOKEEPER_CLIENT_PID);
if (zkConfugiration.getProperties() == null) {
Hashtable<String, Object> zkProperties = new Hashtable<>();
zkProperties.put("zookeeper.url", zookeeperUrl);
zkProperties.put("zookeeper.password", PasswordEncoder.encode(decodedZookeeperPassword));
zkConfugiration.update(zkProperties);
}
}
if (userProps.isEmpty()) {
userProps.put(DEFAULT_ADMIN_USER, decodedZookeeperPassword + ROLE_DELIMITER + DEFAULT_ADMIN_ROLE);
}
String minimumPort = (String) configuration.get("minimum.port");
if (!Strings.isNullOrBlank(minimumPort)) {
this.minport = Integer.valueOf(minimumPort);
}
String maximumPort = (String) configuration.get("maximum.port");
if (!Strings.isNullOrBlank(maximumPort)) {
this.maxport = Integer.valueOf(maximumPort);
}
options = CreateEnsembleOptions.builder().bindAddress(bindAddress).agentEnabled(agentAutoStart).ensembleStart(ensembleAutoStart).zookeeperPassword(decodedZookeeperPassword).zooKeeperServerPort(zookeeperServerPort).zooKeeperServerConnectionPort(zookeeperServerConnectionPort).autoImportEnabled(profilesAutoImport).importPath(profilesAutoImportPath).resolver(localResolver).globalResolver(globalResolver).users(userProps).minimumPort(minport).maximumPort(maxport).profiles(profiles).version(version).build();
}
use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.
the class ContainerBuilder method synchronizeGitRepositories.
/**
* ENTESB-6368: Ensures that local git repository is synchronized with fabric-wide git repository.
*/
protected void synchronizeGitRepositories() {
GitService gitService = io.fabric8.api.gravia.ServiceLocator.awaitService(GitService.class);
GitDataStore gitDataStore = io.fabric8.api.gravia.ServiceLocator.awaitService(GitDataStore.class);
for (int i = 0; i < 10; i++) {
try {
LOG.info("Synchronizing Git repositories");
Iterable<PushResult> results = gitDataStore.doPush(gitService.getGit(), new GitContext().requirePush());
if (results.iterator().hasNext()) {
return;
}
throw new Exception("No reference was pushed");
} catch (Exception e) {
LOG.warn("Synchronization of Git repositories failed: " + e.getMessage());
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException(ie);
}
}
}
}
use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.
the class FabricCreateCommandTest method testLocalFabricCluster.
@Test
public void testLocalFabricCluster() throws Exception {
CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
FabricService fabricService = ServiceLocator.getRequiredService(FabricService.class);
Container[] containers = fabricService.getContainers();
Assert.assertNotNull("Containers not null", containers);
// Test that a provided default password exists
ConfigurationAdmin configurationAdmin = ServiceLocator.getRequiredService(ConfigurationAdmin.class);
org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration(io.fabric8.api.Constants.ZOOKEEPER_CLIENT_PID);
Dictionary<String, Object> dictionary = configuration.getProperties();
Assert.assertEquals("Expected provided zookeeper password", PasswordEncoder.encode(ADMIN_PASSWORD), dictionary.get("zookeeper.password"));
}
use of io.fabric8.kubernetes.api.model in project fabric8 by jboss-fuse.
the class ServiceImplTest method testVersionHistory.
@Test
public void testVersionHistory() {
// the same bundle has been patched twice
Patch patch1 = new Patch(new PatchData("patch1", "First patch", null, null, null, null, null), null);
patch1.setResult(new PatchResult(patch1.getPatchData(), true, System.currentTimeMillis(), new LinkedList<io.fabric8.patch.management.BundleUpdate>(), null));
patch1.getResult().getBundleUpdates().add(new BundleUpdate("my-bsn", "1.1.0", "mvn:groupId/my-bsn/1.1.0", "1.0.0", "mvn:groupId/my-bsn/1.0.0"));
Patch patch2 = new Patch(new PatchData("patch2", "Second patch", null, null, null, null, null), null);
patch2.setResult(new PatchResult(patch1.getPatchData(), true, System.currentTimeMillis(), new LinkedList<io.fabric8.patch.management.BundleUpdate>(), null));
patch2.getResult().getBundleUpdates().add(new BundleUpdate("my-bsn;directive1=true", "1.2.0", "mvn:groupId/my-bsn/1.2.0", "1.1.0", "mvn:groupId/my-bsn/1.1.0"));
Map<String, Patch> patches = new HashMap<String, Patch>();
patches.put("patch1", patch1);
patches.put("patch2", patch2);
// the version history should return the correct URL, even when bundle.getLocation() does not
ServiceImpl.BundleVersionHistory history = new ServiceImpl.BundleVersionHistory(patches);
assertEquals("Should return version from patch result instead of the original location", "mvn:groupId/my-bsn/1.2.0", history.getLocation(createMockBundle("my-bsn", "1.2.0", "mvn:groupId/my-bsn/1.0.0")));
assertEquals("Should return version from patch result instead of the original location", "mvn:groupId/my-bsn/1.1.0", history.getLocation(createMockBundle("my-bsn", "1.1.0", "mvn:groupId/my-bsn/1.0.0")));
assertEquals("Should return original bundle location if no maching version is found in the history", "mvn:groupId/my-bsn/1.0.0", history.getLocation(createMockBundle("my-bsn", "1.0.0", "mvn:groupId/my-bsn/1.0.0")));
assertEquals("Should return original bundle location if no maching version is found in the history", "mvn:groupId/my-bsn/0.9.0", history.getLocation(createMockBundle("my-bsn", "0.9.0", "mvn:groupId/my-bsn/0.9.0")));
}
Aggregations