use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project dekorate by dekorateio.
the class KnativeManifestGenerator method generate.
public void generate(KnativeConfig config) {
Optional<Service> existingService = resourceRegistry.groups().getOrDefault(KNATIVE, new KubernetesListBuilder()).buildItems().stream().filter(i -> i instanceof Service).map(i -> (Service) i).filter(i -> i.getMetadata().getName().equals(config.getName())).findAny();
if (!existingService.isPresent()) {
resourceRegistry.add(KNATIVE, createService(config));
}
Project project = getProject();
Optional<VcsConfig> vcsConfig = configurationRegistry.get(VcsConfig.class);
String remote = vcsConfig.map(VcsConfig::getRemote).orElse(Git.ORIGIN);
boolean httpsPrefered = vcsConfig.map(VcsConfig::isHttpsPreferred).orElse(false);
String vcsUrl = project.getScmInfo() != null && Strings.isNotNullOrEmpty(project.getScmInfo().getRemote().get(Git.ORIGIN)) ? Git.getRemoteUrl(project.getRoot(), remote, httpsPrefered).orElse(Labels.UNKNOWN) : Labels.UNKNOWN;
resourceRegistry.decorate(KNATIVE, new AddVcsUrlAnnotationDecorator(config.getName(), Annotations.VCS_URL, vcsUrl));
resourceRegistry.decorate(KNATIVE, new AddCommitIdAnnotationDecorator());
resourceRegistry.decorate(KNATIVE, new ApplyPortNameDecorator(null, null, config.getHttpTransportVersion() != null ? config.getHttpTransportVersion().name().toLowerCase() : "http1", Ports.webPortNames().toArray(new String[Ports.webPortNames().size()])));
addDecorators(KNATIVE, config);
if (config.getMinScale() != null && config.getMinScale() != 0) {
resourceRegistry.decorate(KNATIVE, new ApplyMinScaleDecorator(config.getName(), config.getMinScale()));
}
if (config.getMaxScale() != null && config.getMaxScale() != 0) {
resourceRegistry.decorate(KNATIVE, new ApplyMaxScaleDecorator(config.getName(), config.getMaxScale()));
}
if (!config.isScaleToZeroEnabled()) {
resourceRegistry.decorate(KNATIVE, new AddConfigMapResourceProvidingDecorator("config-autoscaler"));
resourceRegistry.decorate(KNATIVE, new AddConfigMapDataDecorator("config-autoscaler", "enable-scale-to-zero", String.valueOf(config.isAutoDeployEnabled())));
}
if (Strings.isNotNullOrEmpty(config.getRevisionName())) {
resourceRegistry.decorate(KNATIVE, new ApplyRevisionNameDecorator(config.getName(), config.getRevisionName()));
}
if (config.getRevisionAutoScaling() != null) {
if (config.getRevisionAutoScaling().getMetric() != null && config.getRevisionAutoScaling().getMetric() != AutoscalingMetric.concurrency) {
resourceRegistry.decorate(KNATIVE, new ApplyLocalAutoscalingMetricDecorator(config.getName(), config.getRevisionAutoScaling().getMetric()));
}
if (config.getRevisionAutoScaling().getContainerConcurrency() != null) {
resourceRegistry.decorate(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(config.getName(), config.getRevisionAutoScaling().getContainerConcurrency()));
}
// Local autoscaling configuration
if (config.getRevisionAutoScaling().getAutoScalerClass() != null && config.getRevisionAutoScaling().getAutoScalerClass() != AutoScalerClass.kpa) {
resourceRegistry.decorate(KNATIVE, new ApplyLocalAutoscalingClassDecorator(config.getName(), config.getRevisionAutoScaling().getAutoScalerClass()));
}
if (config.getRevisionAutoScaling().getTarget() != null && config.getRevisionAutoScaling().getTarget() != 0) {
resourceRegistry.decorate(KNATIVE, new ApplyLocalAutoscalingTargetDecorator(config.getName(), config.getRevisionAutoScaling().getTarget()));
}
if (config.getRevisionAutoScaling().getTarget() != null && config.getRevisionAutoScaling().getTarget() != 200 && config.getRevisionAutoScaling().getMetric() == AutoscalingMetric.rps) {
resourceRegistry.decorate(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(config.getName(), config.getRevisionAutoScaling().getTarget()));
}
if (config.getRevisionAutoScaling().getTargetUtilizationPercentage() != null && config.getRevisionAutoScaling().getTargetUtilizationPercentage() != 70) {
resourceRegistry.decorate(KNATIVE, new ApplyLocalContainerConcurrencyDecorator(config.getName(), config.getRevisionAutoScaling().getTargetUtilizationPercentage()));
}
}
// Global autoscaling configuration
if (config.getGlobalAutoScaling() != null) {
if (!isDefault(config.getGlobalAutoScaling())) {
resourceRegistry.decorate(KNATIVE, new AddConfigMapResourceProvidingDecorator("config-autoscaler"));
if (config.getGlobalAutoScaling().getAutoScalerClass() != null && config.getGlobalAutoScaling().getAutoScalerClass() != AutoScalerClass.kpa) {
resourceRegistry.decorate(KNATIVE, new ApplyGlobalAutoscalingClassDecorator(config.getGlobalAutoScaling().getAutoScalerClass()));
}
if (config.getGlobalAutoScaling().getRequestsPerSecond() != null && config.getGlobalAutoScaling().getRequestsPerSecond() != 200) {
resourceRegistry.decorate(KNATIVE, new ApplyGlobalRequestsPerSecondTargetDecorator(config.getGlobalAutoScaling().getRequestsPerSecond()));
}
if (config.getGlobalAutoScaling().getTargetUtilizationPercentage() != null && config.getGlobalAutoScaling().getTargetUtilizationPercentage() != 70) {
resourceRegistry.decorate(KNATIVE, new ApplyGlobalContainerConcurrencyDecorator(config.getGlobalAutoScaling().getTargetUtilizationPercentage()));
}
}
if (config.getGlobalAutoScaling().getContainerConcurrency() != null && config.getGlobalAutoScaling().getContainerConcurrency() != 0) {
resourceRegistry.decorate(KNATIVE, new AddConfigMapResourceProvidingDecorator("config-defaults"));
resourceRegistry.decorate(KNATIVE, new ApplyGlobalContainerConcurrencyDecorator(config.getGlobalAutoScaling().getContainerConcurrency()));
}
}
for (Traffic traffic : config.getTraffic()) {
String revisionName = Strings.isNotNullOrEmpty(config.getRevisionName()) ? config.getRevisionName() : null;
String tag = Strings.isNotNullOrEmpty(traffic.getTag()) ? traffic.getTag() : null;
boolean latestRevision = revisionName == null ? true : traffic.isLatestRevision();
long percentage = traffic.getPercentage();
resourceRegistry.decorate(KNATIVE, new ApplyTrafficDecorator(config.getName(), revisionName, latestRevision, percentage, tag));
}
// Revision specific stuff
for (Container container : config.getSidecars()) {
resourceRegistry.decorate(KNATIVE, new AddSidecarToRevisionDecorator(config.getName(), container));
}
for (SecretVolume volume : config.getSecretVolumes()) {
validateVolume(volume);
resourceRegistry.decorate(KNATIVE, new AddSecretVolumeToRevisionDecorator(volume));
}
for (ConfigMapVolume volume : config.getConfigMapVolumes()) {
validateVolume(volume);
resourceRegistry.decorate(KNATIVE, new AddConfigMapVolumeToRevisionDecorator(volume));
}
for (PersistentVolumeClaimVolume volume : config.getPvcVolumes()) {
resourceRegistry.decorate(KNATIVE, new AddPvcVolumeToRevisionDecorator(volume));
}
for (AzureFileVolume volume : config.getAzureFileVolumes()) {
resourceRegistry.decorate(KNATIVE, new AddAzureFileVolumeToRevisionDecorator(volume));
}
for (AzureDiskVolume volume : config.getAzureDiskVolumes()) {
resourceRegistry.decorate(KNATIVE, new AddAzureDiskVolumeToRevisionDecorator(volume));
}
for (AwsElasticBlockStoreVolume volume : config.getAwsElasticBlockStoreVolumes()) {
resourceRegistry.decorate(KNATIVE, new AddAwsElasticBlockStoreVolumeToRevisionDecorator(volume));
}
for (HostAlias hostAlias : config.getHostAliases()) {
resourceRegistry.decorate(KNATIVE, new AddHostAliasesToRevisionDecorator(hostAlias));
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project Oxalis-AS4 by OxalisCommunity.
the class AbstractMessagingProviderTest method testCreateMessagingHeader.
@Test
public void testCreateMessagingHeader() throws Exception {
TransmissionRequestFactory transmissionRequestFactory = new TransmissionRequestFactory(new NoopContentDetector(), new NoopContentWrapper(), new NoopTagGenerator(), new SbdhHeaderParser(), NoopTracerFactory.create());
TransmissionMessage transmissionMessage;
try (InputStream inputStream = getClass().getResourceAsStream(getPayloadPath())) {
transmissionMessage = transmissionRequestFactory.newInstance(inputStream);
}
Assert.assertNotNull(transmissionMessage.getHeader());
TransmissionRequest transmissionRequest = new DefaultTransmissionRequestFacade(transmissionMessage, Endpoint.of(TransportProfile.PEPPOL_AS2_2_0, null, receiverCert));
HashMap<String, List<String>> headers = new HashMap<>();
headers.put(Content_ID_KEY, Collections.singletonList(Content_ID_VALUE));
headers.put(COMPRESSION_TYPE_KEY, Collections.singletonList(COMPRESSION_TYPE_VALUE));
headers.put(MIME_TYPE_KEY, Collections.singletonList(MIME_TYPE_VALUE));
Attachment attachment = AttachmentUtil.createAttachment(transmissionRequest.getPayload(), headers);
Messaging messaging = messagingProvider.createMessagingHeader(transmissionRequest, new ArrayList<>(Collections.singletonList(attachment)));
UserMessage userMessage = messaging.getUserMessage().get(0);
// MessageInfo
XMLGregorianCalendar timestamp = userMessage.getMessageInfo().getTimestamp();
String messageId = userMessage.getMessageInfo().getMessageId();
Assert.assertNotNull(timestamp);
Assert.assertNotNull(messageId);
// PartyInfo
String to = userMessage.getPartyInfo().getTo().getPartyId().get(0).getValue();
String toType = userMessage.getPartyInfo().getTo().getPartyId().get(0).getType();
String toRole = userMessage.getPartyInfo().getTo().getRole();
String from = userMessage.getPartyInfo().getFrom().getPartyId().get(0).getValue();
String fromType = userMessage.getPartyInfo().getFrom().getPartyId().get(0).getType();
String fromRole = userMessage.getPartyInfo().getFrom().getRole();
Assert.assertEquals(to, RECEIVER);
Assert.assertEquals(toType, PARTY_TYPE);
Assert.assertEquals(toRole, TO_ROLE);
Assert.assertEquals(from, SENDER);
Assert.assertEquals(fromType, PARTY_TYPE);
Assert.assertEquals(fromRole, FROM_ROLE);
// CollaborationInfo
String action = userMessage.getCollaborationInfo().getAction();
Service service = userMessage.getCollaborationInfo().getService();
String conversationId = userMessage.getCollaborationInfo().getConversationId();
Assert.assertEquals(action, ACTION);
Assert.assertEquals(service.getType(), SERVICE_TYPE);
Assert.assertEquals(service.getValue(), SERVICE_VALUE);
Assert.assertNotNull(conversationId);
// MessageProperties
String finalRecipient = userMessage.getMessageProperties().getProperty().stream().filter(p -> "finalRecipient".equalsIgnoreCase(p.getName())).map(Property::getValue).findFirst().get();
String originalSender = userMessage.getMessageProperties().getProperty().stream().filter(p -> "originalSender".equalsIgnoreCase(p.getName())).map(Property::getValue).findFirst().get();
Assert.assertEquals(finalRecipient, FINAL_RECIPIENT);
Assert.assertEquals(originalSender, ORIGINAL_SENDER);
// PayloadInfo
int payloadCount = userMessage.getPayloadInfo().getPartInfo().size();
Assert.assertEquals(payloadCount, 1);
List<Property> partInfo = userMessage.getPayloadInfo().getPartInfo().get(0).getPartProperties().getProperty();
String compressionType = partInfo.stream().filter(pi -> COMPRESSION_TYPE_KEY.equalsIgnoreCase(pi.getName())).map(Property::getValue).findFirst().get();
String mimeType = partInfo.stream().filter(pi -> MIME_TYPE_KEY.equalsIgnoreCase(pi.getName())).map(Property::getValue).findFirst().get();
String contentID = userMessage.getPayloadInfo().getPartInfo().get(0).getHref();
Assert.assertEquals(compressionType, COMPRESSION_TYPE_VALUE);
Assert.assertEquals(mimeType, MIME_TYPE_VALUE);
Assert.assertEquals(contentID, "cid:" + Content_ID_VALUE);
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project api-snippets by TwilioDevEd.
the class Example method main.
public static void main(String[] args) {
// Authenticate with Twilio
Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);
// Update the service webhooks
String newMessageTemplate = "A New message in ${CHANNEL} from ${USER}: " + "${MESSAGE}";
Service service = Service.updater(SERVICE_SID).setNotificationsNewMessageEnabled(true).setNotificationsNewMessageTemplate(newMessageTemplate).setNotificationsNewMessageSound("default").update();
System.out.println(service.getSid());
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method getEndpoints.
/**
* Get endpoints defined in the provided WSDL description.
*
* @param description WSDL 2.0 description
* @return a Map of endpoint names and their URIs.
* @throws APIMgtWSDLException if error occurs while reading endpoints
*/
private Map<String, String> getEndpoints(Description description) throws APIMgtWSDLException {
Service[] services = description.getServices();
Map<String, String> serviceEndpointMap = new HashMap<>();
for (Service service : services) {
Endpoint[] endpoints = service.getEndpoints();
for (Endpoint endpoint : endpoints) {
serviceEndpointMap.put(endpoint.getName().toString(), endpoint.getAddress().toString());
}
}
return serviceEndpointMap;
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Service in project openstack4j by ContainX.
the class BaseOpenStackService method getServiceVersion.
@SuppressWarnings("rawtypes")
protected int getServiceVersion() {
OSClientSession session = OSClientSession.getCurrent();
if (session.getAuthVersion() == AuthVersion.V3) {
SortedSet<? extends Service> services = ((OSClientSession.OSClientSessionV3) session).getToken().getAggregatedCatalog().get(serviceType.getType());
Service service = ((OSClientSession.OSClientSessionV3) session).getToken().getAggregatedCatalog().get(serviceType.getType()).first();
if (services.isEmpty()) {
return 1;
}
return service.getVersion();
} else {
SortedSet<? extends Access.Service> services = ((OSClientSession.OSClientSessionV2) session).getAccess().getAggregatedCatalog().get(serviceType.getType());
Access.Service service = ((OSClientSession.OSClientSessionV2) session).getAccess().getAggregatedCatalog().get(serviceType.getType()).first();
if (services.isEmpty()) {
return 1;
}
return service.getVersion();
}
}
Aggregations