use of io.fabric8.annotations.Protocol in project fabric8 by jboss-fuse.
the class AmqpProtocol method experimentalSnoopConnectionParameters.
public void experimentalSnoopConnectionParameters(final NetSocket socket, final Buffer received, final Handler<ConnectionParameters> handler) {
final AmqpProtocolDecoder h = new AmqpProtocolDecoder(this);
final ConnectionParameters parameters = new ConnectionParameters();
h.errorHandler(new Handler<String>() {
@Override
public void handle(String error) {
LOG.info("STOMP protocol decoding error: " + error);
socket.close();
}
});
h.codecHandler(new Handler<AmqpEvent>() {
EngineFactory engineFactory = new EngineFactoryImpl();
Transport protonTransport = engineFactory.createTransport();
Connection protonConnection = engineFactory.createConnection();
Sasl sasl;
@Override
public void handle(AmqpEvent event) {
switch(event.type) {
case HEADER:
AmqpHeader header = (AmqpHeader) event.decodedFrame;
switch(header.getProtocolId()) {
case 0:
// amqpTransport.sendToAmqp(new AmqpHeader());
break;
// nothing to do..
case 3:
// Client will be using SASL for auth..
sasl = protonTransport.sasl();
// sasl.setMechanisms(new String[] { "ANONYMOUS", "PLAIN" });
sasl.server();
break;
default:
}
processEvent(event);
// Les send back the AMQP response headers so that the client
// can send us the SASL init or AMQP open frames.
Buffer buffer = toBuffer(protonTransport.getOutputBuffer());
protonTransport.outputConsumed();
socket.write(buffer);
break;
default:
processEvent(event);
}
}
private void processEvent(AmqpEvent event) {
byte[] buffer = event.encodedFrame.getBytes();
int offset = 0;
int remaining = buffer.length;
while (remaining > 0) {
try {
int count = protonTransport.input(buffer, offset, remaining);
offset += count;
remaining -= count;
} catch (Throwable e) {
LOG.info("Could not decode AMQP frame: " + e, e);
socket.close();
return;
}
if (sasl != null) {
// TODO: add timeout in case the client is waiting for SASL negotiation
if (sasl.getRemoteMechanisms().length > 0) {
parameters.protocolVirtualHost = getHostname(sasl);
if ("PLAIN".equals(sasl.getRemoteMechanisms()[0])) {
byte[] data = new byte[sasl.pending()];
sasl.recv(data, 0, data.length);
Buffer[] parts = split(new Buffer(data), (byte) 0);
if (parts.length > 0) {
parameters.protocolUser = parts[0].toString();
}
// We are done!
handler.handle(parameters);
}
}
}
if (protonConnection.getLocalState() == EndpointState.UNINITIALIZED && protonConnection.getRemoteState() != EndpointState.UNINITIALIZED) {
// If we get here them the connection was not using SASL.. we can get the hostname
// info from the open frame.
parameters.protocolVirtualHost = protonConnection.getRemoteHostname();
// We are done!
handler.handle(parameters);
}
}
}
});
socket.dataHandler(h);
h.handle(received);
}
use of io.fabric8.annotations.Protocol in project strimzi by strimzi.
the class AbstractModel method createContainerPort.
protected ContainerPort createContainerPort(String name, int port, String protocol) {
ContainerPort containerPort = new ContainerPortBuilder().withName(name).withProtocol(protocol).withContainerPort(port).build();
log.trace("Created container port {}", containerPort);
return containerPort;
}
use of io.fabric8.annotations.Protocol in project strimzi by strimzi.
the class AbstractModel method createServicePort.
protected ServicePort createServicePort(String name, int port, int targetPort, String protocol) {
ServicePort servicePort = new ServicePortBuilder().withName(name).withProtocol(protocol).withPort(port).withNewTargetPort(targetPort).build();
log.trace("Created service port {}", servicePort);
return servicePort;
}
use of io.fabric8.annotations.Protocol in project fabric8-maven-plugin by fabric8io.
the class AbstractLiveEnricher method getExternalServiceURL.
/**
* Returns the external access to the given service name
*
* @param serviceName name of the service
* @param protocol URL protocol such as <code>http</code>
*/
protected String getExternalServiceURL(String serviceName, String protocol) {
if (!isOnline()) {
getLog().info("Not looking for service " + serviceName + " as we are in offline mode");
return null;
} else {
try {
KubernetesClient kubernetes = getKubernetes();
String ns = kubernetes.getNamespace();
if (Strings.isNullOrBlank(ns)) {
ns = getNamespace();
}
Service service = kubernetes.services().inNamespace(ns).withName(serviceName).get();
return service != null ? KubernetesHelper.getServiceURL(kubernetes, serviceName, ns, protocol, true) : null;
} catch (Throwable e) {
Throwable cause = e;
boolean notFound = false;
boolean connectError = false;
Stack<Throwable> stack = unfoldExceptions(e);
while (!stack.isEmpty()) {
Throwable t = stack.pop();
if (t instanceof ConnectException || "No route to host".equals(t.getMessage())) {
getLog().warn("Cannot connect to Kubernetes to find URL for service %s : %s", serviceName, cause.getMessage());
return null;
} else if (t instanceof IllegalArgumentException || t.getMessage() != null && t.getMessage().matches("^No.*found.*$")) {
getLog().warn("%s", cause.getMessage());
return null;
}
;
}
getLog().warn("Cannot find URL for service %s : %s", serviceName, cause.getMessage());
return null;
}
}
}
use of io.fabric8.annotations.Protocol in project fabric8-maven-plugin by fabric8io.
the class ImportMojo method ensureExternalGitSecretsAreSetupFor.
protected void ensureExternalGitSecretsAreSetupFor(KubernetesClient kubernetes, String namespace, String gitRemoteURL) throws MojoExecutionException {
String secretNamespace = getSecretNamespace();
ensureNamespaceExists(kubernetes, secretNamespace);
ConfigMap configMap = getSecretGitConfigMap(kubernetes, namespace, secretNamespace);
String host = GitUtils.getGitHostName(gitRemoteURL);
if (host == null) {
host = "default";
}
String protocol = GitUtils.getGitProtocol(gitRemoteURL);
boolean isSsh = Objects.equal("ssh", protocol);
String currentSecretName = configMap.getData().get(host);
if (currentSecretName == null) {
currentSecretName = createGitSecretName(namespace, host);
}
Secret secret = findOrCreateGitSecret(kubernetes, currentSecretName, host);
if (isSsh) {
// lets see if we need to import ssh keys
Map<String, String> secretData = secret.getData();
if (secretData == null) {
secretData = new HashMap<>();
}
if (!secretData.containsKey(PROPERTY_PRIVATE_KEY) || !secretData.containsKey(PROPERTY_PUBLIC_KEY)) {
String answer = null;
try {
answer = prompter.prompt("Would you like to import your local SSH public/private key pair from your ~/.ssh folder? (Y/n)");
} catch (PrompterException e) {
log.warn("Failed to get prompt: %s", e);
}
if (answer != null && answer.trim().isEmpty() || answer.trim().toUpperCase().startsWith("Y")) {
chooseSshKeyPairs(secretData, host);
secret.setData(secretData);
}
}
} else {
// if empty or retrying lets re-enter the user/pwd
getGogsSecretField(kubernetes, secret, host, "username");
getGogsSecretField(kubernetes, secret, host, "password");
}
createOrUpdateSecret(kubernetes, secret);
updateSecretGitConfigMap(kubernetes, secretNamespace, configMap, host, currentSecretName);
}
Aggregations