use of io.fabric8.arquillian.kubernetes.Session in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManagerTest method mockMojoParams.
private MojoParameters mockMojoParams(MavenProject project) {
Settings settings = new Settings();
ArtifactRepository localRepository = new MockUp<ArtifactRepository>() {
@Mock
public String getBasedir() {
return "repository";
}
}.getMockInstance();
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
use of io.fabric8.arquillian.kubernetes.Session in project docker-maven-plugin by fabric8io.
the class AbstractDockerMojo method execute.
/**
* Entry point for this plugin. It will set up the helper class and then calls
* {@link #executeInternal(ServiceHub)}
* which must be implemented by subclass.
*
* @throws MojoExecutionException
* @throws MojoFailureException
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!skip) {
log = new AnsiLogger(getLog(), useColor, verbose, !settings.getInteractiveMode(), getLogPrefix());
authConfigFactory.setLog(log);
LogOutputSpecFactory logSpecFactory = new LogOutputSpecFactory(useColor, logStdout, logDate);
ConfigHelper.validateExternalPropertyActivation(project, images);
// The 'real' images configuration to use (configured images + externally resolved images)
this.minimalApiVersion = initImageConfiguration(getBuildTimestamp());
DockerAccess access = null;
try {
if (isDockerAccessRequired()) {
DockerAccessFactory.DockerAccessContext dockerAccessContext = getDockerAccessContext();
access = dockerAccessFactory.createDockerAccess(dockerAccessContext);
}
ServiceHub serviceHub = serviceHubFactory.createServiceHub(project, session, access, log, logSpecFactory);
executeInternal(serviceHub);
} catch (DockerAccessException | ExecException exp) {
logException(exp);
throw new MojoExecutionException(log.errorMessage(exp.getMessage()), exp);
} catch (MojoExecutionException exp) {
logException(exp);
throw exp;
} finally {
if (access != null) {
access.shutdown();
}
}
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class ContainerConnectAction method executSshCommand.
/**
* Executes the ssh command.
*/
private void executSshCommand(CommandSession session, String username, String password, String hostname, String port, String cmd) throws Exception {
if (cmd == null || cmd.length() == 0) {
// ENTESB-6826: we're connecting in "shell" mode, which isn't wise when running from bin/client or ssh
if (session.getKeyboard().getClass().getName().equals("org.apache.sshd.common.channel.ChannelPipedInputStream")) {
System.err.println("When connecting to remote container using \"fabric:container-connect\" using ssh or bin/client, please establish SSH session (run bin/client) first and then run \"fabric:container-connect\"");
return;
}
}
// Create the client from prototype
SshClient client = createClient();
String agentSocket;
if (this.session.get(SshAgent.SSH_AUTHSOCKET_ENV_NAME) != null) {
agentSocket = this.session.get(SshAgent.SSH_AUTHSOCKET_ENV_NAME).toString();
client.getProperties().put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, agentSocket);
}
try {
ConnectFuture future = client.connect(hostname, Integer.parseInt(port));
future.await();
sshSession = future.getSession();
Object oldIgnoreInterrupts = this.session.get(Console.IGNORE_INTERRUPTS);
this.session.put(Console.IGNORE_INTERRUPTS, Boolean.TRUE);
try {
System.out.println("Connected");
boolean authed = false;
if (!authed) {
if (username == null) {
throw new FabricAuthenticationException("No username specified.");
}
log.debug("Prompting user for password");
String pwd = password != null ? password : ShellUtils.readLine(session, "Password: ", true);
sshSession.authPassword(username, pwd);
int ret = sshSession.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0);
if ((ret & ClientSession.AUTHED) == 0) {
System.err.println("Password authentication failed");
} else {
authed = true;
}
}
if (!authed) {
throw new FabricAuthenticationException("Failed to authenticate.");
}
// If user is authenticated credentials to session for future use.
ShellUtils.storeFabricCredentials(session, username, password);
ClientChannel channel;
if (cmd != null && cmd.length() > 0) {
channel = sshSession.createChannel("exec", cmd);
channel.setIn(new ByteArrayInputStream(new byte[0]));
} else {
channel = sshSession.createChannel("shell");
channel.setIn(new NoCloseInputStream(System.in));
((ChannelShell) channel).setPtyColumns(ShellUtils.getTermWidth(session));
((ChannelShell) channel).setupSensibleDefaultPty();
((ChannelShell) channel).setAgentForwarding(true);
}
channel.setOut(new NoCloseOutputStream(System.out));
channel.setErr(new NoCloseOutputStream(System.err));
channel.open();
channel.waitFor(ClientChannel.CLOSED, 0);
} finally {
session.put(Console.IGNORE_INTERRUPTS, oldIgnoreInterrupts);
sshSession.close(false);
}
} finally {
client.stop();
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class JoinAction method doExecute.
@Override
protected Object doExecute() throws Exception {
if (nonManaged) {
profile = "unmanaged";
}
String oldName = runtimeProperties.getRuntimeIdentity();
if (System.getenv("OPENSHIFT_BROKER_HOST") != null && containerName != null) {
System.err.println("Containers in OpenShift cannot be renamed");
return null;
}
if (containerName == null) {
containerName = oldName;
}
FabricValidations.validateContainerName(containerName);
Configuration bootConfiguration = configAdmin.getConfiguration(BootstrapConfiguration.COMPONENT_PID, null);
Configuration dataStoreConfiguration = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
Configuration configZook = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
if (configZook.getProperties() != null && configZook.getProperties().get("zookeeper.url") != null) {
System.err.println("This container is already connected to a fabric");
return null;
}
Dictionary<String, Object> bootProperties = bootConfiguration.getProperties();
if (bootProperties == null) {
bootProperties = new Hashtable<>();
}
if (resolver != null) {
bootProperties.put(ZkDefs.LOCAL_RESOLVER_PROPERTY, resolver);
}
if (manualIp != null) {
bootProperties.put(ZkDefs.MANUAL_IP, manualIp);
}
if (bindAddress != null) {
bootProperties.put(ZkDefs.BIND_ADDRESS, bindAddress);
}
zookeeperPassword = zookeeperPassword != null ? zookeeperPassword : ShellUtils.retrieveFabricZookeeperPassword(session);
if (zookeeperPassword == null) {
zookeeperPassword = promptForZookeeperPassword();
}
if (zookeeperPassword == null || zookeeperPassword.isEmpty()) {
System.out.println("No password specified. Cannot join fabric ensemble.");
return null;
}
ShellUtils.storeZookeeperPassword(session, zookeeperPassword);
log.debug("Encoding ZooKeeper password.");
String encodedPassword = PasswordEncoder.encode(zookeeperPassword);
bootProperties.put(ZkDefs.MINIMUM_PORT, String.valueOf(minimumPort));
bootProperties.put(ZkDefs.MAXIMUM_PORT, String.valueOf(maximumPort));
Hashtable<String, Object> dataStoreProperties = new Hashtable<String, Object>();
Configuration cfg = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
Dictionary<String, Object> props = cfg.getProperties();
if (props != null) {
for (Enumeration<String> keys = cfg.getProperties().keys(); keys.hasMoreElements(); ) {
String k = keys.nextElement();
dataStoreProperties.put(k, cfg.getProperties().get(k));
}
}
augmentDataStoreProperties(zookeeperPassword, dataStoreProperties);
if (!containerName.equals(oldName)) {
if (force || permissionToRenameContainer()) {
if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
return null;
}
bootProperties.put(SystemProperties.KARAF_NAME, containerName);
// Ensure that if we bootstrap CuratorFramework via RuntimeProperties password is set before the URL.
bootProperties.put("zookeeper.password", encodedPassword);
bootProperties.put("zookeeper.url", zookeeperUrl);
// Rename the container
Path propsPath = runtimeProperties.getConfPath().resolve("system.properties");
Properties systemProps = new Properties(propsPath.toFile());
systemProps.put(SystemProperties.KARAF_NAME, containerName);
// Also pass zookeeper information so that the container can auto-join after the restart.
systemProps.put("zookeeper.url", zookeeperUrl);
systemProps.put("zookeeper.password", encodedPassword);
systemProps.save();
System.setProperty("runtime.id", containerName);
System.setProperty(SystemProperties.KARAF_NAME, containerName);
System.setProperty("karaf.restart", "true");
System.setProperty("karaf.restart.clean", "false");
if (!nonManaged) {
installBundles();
}
// it's only a(n almost certain) way of synchronizing CM and ManagedService.update()
if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, bootConfiguration, bootProperties, 10, TimeUnit.SECONDS)) {
log.warn("Timeout waiting for update of PID: {}", BootstrapConfiguration.COMPONENT_PID);
}
if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, dataStoreConfiguration, dataStoreProperties, 10, TimeUnit.SECONDS)) {
log.warn("Timeout waiting for update of PID: {}", Constants.DATASTORE_PID);
}
// we don't want fileinstall to trigger ConfigAdmin update
Bundle fileinstall = new BundleUtils(bundleContext).findBundle("org.apache.felix.fileinstall");
if (fileinstall != null) {
fileinstall.stop(Bundle.STOP_TRANSIENT);
}
persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
// Restart the container
bundleContext.getBundle(0).stop();
return null;
} else {
return null;
}
} else {
bootConfiguration.update(bootProperties);
dataStoreConfiguration.update(dataStoreProperties);
persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
return null;
}
Configuration config = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("zookeeper.url", zookeeperUrl);
properties.put("zookeeper.password", PasswordEncoder.encode(encodedPassword));
config.setBundleLocation(null);
config.update(properties);
if (!nonManaged) {
installBundles();
}
return null;
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.
the class AetherBasedResolver method collectDependencies.
protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
final DefaultRepositorySystemSession session = newSession();
try {
List<RemoteRepository> repos = selectRepositories();
assignProxyAndMirrors(repos);
ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
repos.addAll(artifactDescriptorResult.getRepositories());
Dependency rootDependency = new Dependency(root, null);
List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
GenericVersionScheme versionScheme = new GenericVersionScheme();
rootNode.setVersion(versionScheme.parseVersion(pomVersion));
rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
DependencyNode pomNode = rootNode;
// final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {
@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
return this;
}
@Override
public boolean selectDependency(Dependency dependency) {
try {
return !DependencyFilters.matches(dependency, shouldExclude);
} catch (Exception e) {
failedToMakeDependencyTree(dependency, e);
return false;
}
}
});
session.setDependencySelector(dependencySelector);
// work on the root dependency directly?
if (true) {
for (Dependency dependency : dependencies) {
DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
if (node != null) {
pomNode.getChildren().add(node);
}
}
} else {
DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
if (node != null) {
pomNode = node;
}
}
// now lets transform the dependency tree to remove different versions for the same artifact
final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {
Map<Object, Object> map = new HashMap<>();
public RepositorySystemSession getSession() {
return session;
}
public Object get(Object key) {
return map.get(key);
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
};
DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
pomNode = transformer.transformGraph(pomNode, tranformContext);
transformer = new DuplicateTransformer();
pomNode = transformer.transformGraph(pomNode, tranformContext);
return pomNode;
} finally {
releaseSession(session);
}
}
Aggregations