use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class MQCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
MQBrokerConfigDTO dto = createDTO();
Profile profile = MQManager.createOrUpdateProfile(dto, fabricService, runtimeProperties);
if (profile == null) {
return null;
}
String profileId = profile.getId();
System.out.println("MQ profile " + profileId + " ready");
// assign profile to existing containers
if (assign != null) {
String[] assignContainers = assign.split(",");
MQManager.assignProfileToContainers(fabricService, profile, assignContainers);
}
// create containers
if (create != null) {
String[] createContainers = create.split(",");
List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders(dto, fabricService, "child", profileId, dto.version(), createContainers);
for (CreateContainerBasicOptions.Builder builder : builderList) {
CreateContainerMetadata[] metadatas;
try {
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
builder = childBuilder.jmxUser(username).jmxPassword(password);
}
metadatas = fabricService.createContainers(builder.build());
// check if there was a FabricAuthenticationException as failure then we can try again
if (metadatas != null) {
for (CreateContainerMetadata meta : metadatas) {
if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) {
throw (FabricAuthenticationException) meta.getFailure();
}
}
}
ShellUtils.storeFabricCredentials(session, username, password);
} catch (FabricAuthenticationException fae) {
// If authentication fails, prompts for credentials and try again.
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
promptForJmxCredentialsIfNeeded();
metadatas = fabricService.createContainers(childBuilder.jmxUser(username).jmxPassword(password).build());
ShellUtils.storeFabricCredentials(session, username, password);
}
}
}
}
return null;
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class PatchApplyAction method doExecute.
@Override
protected Object doExecute() throws Exception {
List<Version> versions;
ProfileService profileService = fabricService.adapt(ProfileService.class);
if (versionId != null && !versionId.isEmpty()) {
Version version = profileService.getRequiredVersion(versionId);
versions = Collections.singletonList(version);
} else if (allVersions) {
versions = new ArrayList<>();
for (String versionId : profileService.getVersions()) {
versions.add(profileService.getRequiredVersion(versionId));
}
} else {
versions = Collections.singletonList(fabricService.getRequiredDefaultVersion());
}
username = username != null && !username.isEmpty() ? username : ShellUtils.retrieveFabricUser(session);
password = password != null ? password : ShellUtils.retrieveFabricUserPassword(session);
promptForJmxCredentialsIfNeeded();
for (Version version : versions) {
fabricService.getPatchService().applyPatch(version, patch, username, password);
}
return null;
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class SshContainerProvider method start.
@Override
public void start(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
try {
String script = buildStartScript(container.getId(), options);
session = createSession(options);
runScriptOnHost(session, script);
} catch (Throwable t) {
LOGGER.error("Failed to start container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class SshContainerProvider method uploadTo.
protected void uploadTo(Session session, URL url, String path) {
Channel channel = null;
try (InputStream is = url.openStream()) {
channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
final CountDownLatch uploadLatch = new CountDownLatch(1);
sftpChannel.put(is, path, new SftpProgressMonitor() {
@Override
public void init(int op, String src, String dest, long max) {
}
@Override
public boolean count(long count) {
try {
return is.available() > 0;
} catch (IOException e) {
return false;
}
}
@Override
public void end() {
uploadLatch.countDown();
}
}, ChannelSftp.OVERWRITE);
uploadLatch.await(10, TimeUnit.MINUTES);
} catch (Exception e) {
LOGGER.warn("Failed to upload. Will attempt downloading distribution via maven.");
} finally {
if (channel != null) {
channel.disconnect();
}
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class SshContainerProvider method createSession.
protected Session createSession(CreateSshContainerOptions options) throws Exception {
Session session = null;
Exception connectException = null;
for (int i = 0; i <= options.getSshRetries(); i++) {
if (i > 0) {
long delayMs = (long) (200L * Math.pow(i, 2));
Thread.sleep(delayMs);
}
try {
JSch jsch = new JSch();
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
byte[] privateKey = readFile(options.getPrivateKeyFile());
byte[] passPhrase = options.getPassPhrase() != null ? options.getPassPhrase().getBytes() : null;
if (privateKey != null && options.getPassword() == null) {
jsch.addIdentity(options.getUsername(), privateKey, null, passPhrase);
session = jsch.getSession(options.getUsername(), options.getHost(), options.getPort());
config.put("PreferredAuthentications", "publickey");
} else {
session = jsch.getSession(options.getUsername(), options.getHost(), options.getPort());
session.setPassword(options.getPassword());
config.put("PreferredAuthentications", "password,keyboard-interactive");
}
session.setTimeout(60000);
session.setConfig(config);
session.connect();
connectException = null;
break;
} catch (Exception from) {
connectException = from;
if (session != null && session.isConnected()) {
session.disconnect();
}
session = null;
}
}
if (connectException != null) {
throw connectException;
}
return session;
}
Aggregations