use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project kubernetes by ballerinax.
the class KubernetesPlugin method process.
@Override
public void process(EndpointNode endpointNode, List<AnnotationAttachmentNode> annotations) {
String endpointName = endpointNode.getName().getValue();
ServiceModel serviceModel = null;
setCanProcess(true);
for (AnnotationAttachmentNode attachmentNode : annotations) {
String annotationKey = attachmentNode.getAnnotationName().getValue();
try {
switch(annotationKey) {
case "Service":
serviceModel = kubernetesAnnotationProcessor.processServiceAnnotation(endpointName, attachmentNode);
kubernetesDataHolder.addServiceModel(endpointName, serviceModel);
break;
case "Deployment":
kubernetesDataHolder.setDeploymentModel(kubernetesAnnotationProcessor.processDeployment(attachmentNode));
break;
default:
break;
}
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, endpointNode.getPosition(), e.getMessage());
}
}
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangEndpoint) endpointNode).configurationExpr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
String key = keyValue.getKey().toString();
switch(key) {
case "port":
int port = Integer.parseInt(keyValue.getValue().toString());
kubernetesDataHolder.addPort(port);
if (serviceModel != null) {
serviceModel.setPort(port);
}
break;
case "secureSocket":
List<BLangRecordLiteral.BLangRecordKeyValue> sslKeyValues = ((BLangRecordLiteral) keyValue.valueExpr).getKeyValuePairs();
try {
Set<SecretModel> secretModels = kubernetesAnnotationProcessor.processSecureSocketAnnotation(endpointName, sslKeyValues);
kubernetesDataHolder.addEndpointSecret(endpointName, secretModels);
kubernetesDataHolder.addSecrets(secretModels);
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, null, e.getMessage());
}
break;
default:
break;
}
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project kubernetes by ballerinax.
the class KubernetesPlugin method process.
@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
setCanProcess(true);
Set<String> endpoints = extractEndpointName(serviceNode);
for (AnnotationAttachmentNode attachmentNode : annotations) {
String annotationKey = attachmentNode.getAnnotationName().getValue();
try {
switch(annotationKey) {
case "Ingress":
kubernetesDataHolder.addIngressModel(kubernetesAnnotationProcessor.processIngressAnnotation(serviceNode.getName().getValue(), attachmentNode), endpoints);
break;
case "HPA":
kubernetesDataHolder.setPodAutoscalerModel(kubernetesAnnotationProcessor.processPodAutoscalerAnnotation(attachmentNode));
break;
case "Deployment":
kubernetesDataHolder.setDeploymentModel(kubernetesAnnotationProcessor.processDeployment(attachmentNode));
break;
case "Secret":
kubernetesDataHolder.addSecrets(kubernetesAnnotationProcessor.processSecrets(attachmentNode));
break;
case "ConfigMap":
try {
kubernetesDataHolder.addConfigMaps(kubernetesAnnotationProcessor.processConfigMap(attachmentNode));
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage());
}
break;
case "PersistentVolumeClaim":
try {
kubernetesDataHolder.addPersistentVolumeClaims(kubernetesAnnotationProcessor.processPersistentVolumeClaim(attachmentNode));
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage());
}
break;
default:
break;
}
} catch (KubernetesPluginException e) {
dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage());
}
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class HTTPServiceCompilerPlugin method process.
@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
for (AnnotationAttachmentNode annotation : annotations) {
if (!PROTOCOL_PACKAGE_HTTP.equals(((BLangAnnotationAttachment) annotation).annotationSymbol.pkgID.name.value)) {
continue;
}
if (annotation.getAnnotationName().getValue().equals(ANN_NAME_HTTP_SERVICE_CONFIG) || annotation.getAnnotationName().getValue().equals(WebSocketConstants.WEBSOCKET_ANNOTATION_CONFIGURATION)) {
handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation);
}
}
if (HttpConstants.HTTP_SERVICE_TYPE.equals(serviceNode.getServiceTypeStruct().getTypeName().getValue())) {
List<BLangResource> resources = (List<BLangResource>) serviceNode.getResources();
resources.forEach(resource -> ResourceSignatureValidator.validate(resource.getParameters()));
}
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class ServiceProtoUtils method isServerStreaming.
private static boolean isServerStreaming(ResourceNode resourceNode) {
boolean serverStreaming = false;
for (AnnotationAttachmentNode annotationNode : resourceNode.getAnnotationAttachments()) {
if (!ANN_RESOURCE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) {
continue;
}
if (annotationNode.getExpression() instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) annotationNode.getExpression()).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue attributeNode : attributes) {
String attributeName = attributeNode.getKey().toString();
String attributeValue = attributeNode.getValue() != null ? attributeNode.getValue().toString() : null;
if (ANN_ATTR_RESOURCE_SERVER_STREAM.equals(attributeName)) {
serverStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue);
}
}
}
}
return serverStreaming;
}
use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.
the class AnnotationDesugar method generateAnnotations.
private void generateAnnotations(AnnotatableNode node, String key, BLangFunction target, BLangVariable annMapVar) {
if (node.getAnnotationAttachments().size() == 0) {
return;
}
BLangVariable entryVar = createAnnotationMapEntryVar(key, annMapVar, target.body, target.symbol);
int annCount = 0;
for (AnnotationAttachmentNode attachment : node.getAnnotationAttachments()) {
initAnnotation((BLangAnnotationAttachment) attachment, entryVar, target.body, target.symbol, annCount++);
}
}
Aggregations