use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project webtools.servertools by eclipse.
the class Tomcat70Configuration method getServerPorts.
/**
* Returns a list of ServerPorts that this configuration uses.
*
* @return java.util.List
*/
public List getServerPorts() {
List<ServerPort> ports = new ArrayList<ServerPort>();
// first add server port
try {
int port = Integer.parseInt(server.getPort());
ports.add(new ServerPort("server", Messages.portServer, port, "TCPIP"));
} catch (Exception e) {
// ignore
}
// add connectors
try {
String instanceServiceName = serverInstance.getService().getName();
int size = server.getServiceCount();
for (int i = 0; i < size; i++) {
Service service = server.getService(i);
int size2 = service.getConnectorCount();
for (int j = 0; j < size2; j++) {
Connector connector = service.getConnector(j);
String name = "HTTP/1.1";
String protocol2 = "HTTP";
boolean advanced = true;
String[] contentTypes = null;
int port = -1;
try {
port = Integer.parseInt(connector.getPort());
} catch (Exception e) {
// ignore
}
String protocol = connector.getProtocol();
if (protocol != null && protocol.length() > 0) {
if (protocol.startsWith("HTTP")) {
name = protocol;
} else if (protocol.startsWith("AJP")) {
name = protocol;
protocol2 = "AJP";
} else {
// Get Tomcat equivalent name if protocol handler class specified
name = protocolHandlerMap.get(protocol);
if (name != null) {
// Prepare simple protocol string for ServerPort protocol
int index = name.indexOf('/');
if (index > 0)
protocol2 = name.substring(0, index);
else
protocol2 = name;
} else // Specified protocol is unknown, just use as is
{
name = protocol;
protocol2 = protocol;
}
}
}
if (protocol2.toLowerCase().equals("http"))
contentTypes = new String[] { "web", "webservices" };
String secure = connector.getSecure();
if (secure != null && secure.length() > 0) {
name = "SSL";
protocol2 = "SSL";
} else
advanced = false;
String portId;
if (instanceServiceName != null && instanceServiceName.equals(service.getName()))
portId = Integer.toString(j);
else
portId = i + "/" + j;
ports.add(new ServerPort(portId, name, port, protocol2, contentTypes, advanced));
}
}
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error getting server ports", e);
}
return ports;
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project webtools.servertools by eclipse.
the class Tomcat70Configuration method modifyServerPort.
/**
* Modify the port with the given id.
*
* @param id java.lang.String
* @param port int
*/
public void modifyServerPort(String id, int port) {
try {
if ("server".equals(id)) {
server.setPort(port + "");
isServerDirty = true;
firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new Integer(port));
return;
}
int i = id.indexOf("/");
// If a connector in the instance Service
if (i < 0) {
int connNum = Integer.parseInt(id);
Connector connector = serverInstance.getConnector(connNum);
if (connector != null) {
connector.setPort(port + "");
isServerDirty = true;
firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new Integer(port));
}
} else // Else a connector in another Service
{
int servNum = Integer.parseInt(id.substring(0, i));
int connNum = Integer.parseInt(id.substring(i + 1));
Service service = server.getService(servNum);
Connector connector = service.getConnector(connNum);
connector.setPort(port + "");
isServerDirty = true;
firePropertyChangeEvent(MODIFY_PORT_PROPERTY, id, new Integer(port));
}
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Error modifying server port " + id, e);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project kubernetes by ballerinax.
the class KnativeServiceHandler method generate.
/**
* Generate kubernetes deployment definition from annotation.
*
* @param serviceModel @{@link ServiceModel} definition
* @throws KubernetesPluginException If an error occurs while generating artifact.
*/
private void generate(ServiceModel serviceModel) throws KubernetesPluginException {
List<ContainerPort> containerPorts = null;
if (serviceModel.getPorts() != null) {
containerPorts = populatePorts(serviceModel.getPorts());
}
Container container = generateContainer(serviceModel, containerPorts);
Service knativeSvc = new ServiceBuilder().withNewMetadata().withName(serviceModel.getName()).withNamespace(knativeDataHolder.getNamespace()).withAnnotations(serviceModel.getAnnotations()).withLabels(serviceModel.getLabels()).endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainerConcurrency((long) serviceModel.getContainerConcurrency()).withTimeoutSeconds((long) serviceModel.getTimeoutSeconds()).withContainers(container).withInitContainers(generateInitContainer(serviceModel)).withVolumes(populateVolume(serviceModel)).endSpec().endTemplate().endSpec().build();
try {
String knativeSvcContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(knativeSvc);
KnativeUtils.writeToFile(knativeSvcContent, KNATIVE_SVC_FILE_POSTFIX + YAML);
} catch (IOException e) {
String errorMessage = "error while generating yaml file for deployment: " + serviceModel.getName();
throw new KubernetesPluginException(errorMessage, e);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project kubernetes-client by fabric8io.
the class ServiceTest method testCreate.
@Test
@DisplayName("Should Create a Knative Service")
void testCreate() {
Service service = new ServiceBuilder().withNewMetadata().withName("service").endMetadata().build();
server.expect().post().withPath("/apis/serving.knative.dev/v1/namespaces/ns2/services").andReturn(HttpURLConnection.HTTP_OK, service).once();
service = client.services().inNamespace("ns2").create(service);
assertNotNull(service);
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project kubernetes-client by fabric8io.
the class ServiceTest method testGet.
@Test
@DisplayName("Should get a Knative Service")
void testGet() {
Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().build();
server.expect().get().withPath("/apis/serving.knative.dev/v1/namespaces/ns2/services/service2").andReturn(HttpURLConnection.HTTP_OK, service2).once();
Service service = client.services().inNamespace("ns2").withName("service2").get();
assertNotNull(service);
assertEquals("service2", service.getMetadata().getName());
}
Aggregations