use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processPersistentVolumeClaim.
/**
* Process PersistentVolumeClaim annotations.
*
* @param attachmentNode Attachment Node
* @return Set of @{@link ConfigMapModel} objects
*/
Set<PersistentVolumeClaimModel> processPersistentVolumeClaim(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<PersistentVolumeClaimModel> volumeClaimModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
List<BLangExpression> secretAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : secretAnnotation) {
PersistentVolumeClaimModel claimModel = new PersistentVolumeClaimModel();
List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
VolumeClaimConfig volumeMountConfig = VolumeClaimConfig.valueOf(annotation.getKey().toString());
String annotationValue = resolveValue(annotation.getValue().toString());
switch(volumeMountConfig) {
case name:
claimModel.setName(getValidName(annotationValue));
break;
case mountPath:
claimModel.setMountPath(annotationValue);
break;
case accessMode:
claimModel.setAccessMode(annotationValue);
break;
case volumeClaimSize:
claimModel.setVolumeClaimSize(annotationValue);
break;
case readOnly:
claimModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
volumeClaimModels.add(claimModel);
}
}
return volumeClaimModels;
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processConfigMap.
/**
* Process ConfigMap annotations.
*
* @param attachmentNode Attachment Node
* @return Set of @{@link ConfigMapModel} objects
*/
Set<ConfigMapModel> processConfigMap(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<ConfigMapModel> configMapModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
List<BLangExpression> configAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
ConfigMapModel configMapModel = new ConfigMapModel();
List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
String annotationValue = resolveValue(annotation.getValue().toString());
switch(volumeMountConfig) {
case name:
configMapModel.setName(getValidName(annotationValue));
break;
case mountPath:
configMapModel.setMountPath(annotationValue);
break;
case isBallerinaConf:
configMapModel.setBallerinaConf(Boolean.parseBoolean(annotationValue));
break;
case data:
List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
configMapModel.setData(getDataForConfigMap(data));
break;
case readOnly:
configMapModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
configMapModels.add(configMapModel);
}
}
return configMapModels;
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processPodAutoscalerAnnotation.
/**
* Process annotations and create service model object.
*
* @param attachmentNode annotation attachment node.
* @return Service model object
*/
PodAutoscalerModel processPodAutoscalerAnnotation(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
PodAutoscalerModel podAutoscalerModel = new PodAutoscalerModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
PodAutoscalerConfiguration podAutoscalerConfiguration = PodAutoscalerConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(podAutoscalerConfiguration) {
case name:
podAutoscalerModel.setName(getValidName(annotationValue));
break;
case labels:
podAutoscalerModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case cpuPercentage:
podAutoscalerModel.setCpuPercentage(Integer.parseInt(annotationValue));
break;
case minReplicas:
podAutoscalerModel.setMinReplicas(Integer.parseInt(annotationValue));
break;
case maxReplicas:
podAutoscalerModel.setMaxReplicas(Integer.parseInt(annotationValue));
break;
default:
break;
}
}
return podAutoscalerModel;
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project ballerina by ballerina-lang.
the class CommandUtil method getServiceDocumentationByPosition.
/**
* Get the Documentation attachment for the service.
* @param bLangPackage BLangPackage built
* @param line Start line of the service in the source
* @return {@link String} Documentation attachment for the service
*/
static DocAttachmentInfo getServiceDocumentationByPosition(BLangPackage bLangPackage, int line) {
// TODO: Currently resource position is invalid and we use the annotation attachment positions.
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangService) {
BLangService serviceNode = (BLangService) topLevelNode;
DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(serviceNode.getPosition());
List<BLangAnnotationAttachment> annotationAttachments = serviceNode.getAnnotationAttachments();
if (!annotationAttachments.isEmpty()) {
DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
if (lastAttachmentPos.getEndLine() < line && line < servicePos.getEndLine()) {
return getServiceNodeDocumentation(serviceNode, lastAttachmentPos.getEndLine() + 1);
}
} else if (servicePos.getStartLine() == line) {
return getServiceNodeDocumentation(serviceNode, line);
}
}
}
return null;
}
use of org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment in project ballerina by ballerina-lang.
the class CompilerPluginRunner method notifyProcessors.
private void notifyProcessors(List<BLangAnnotationAttachment> attachments, BiConsumer<CompilerPlugin, List<AnnotationAttachmentNode>> notifier) {
Map<CompilerPlugin, List<AnnotationAttachmentNode>> attachmentMap = new HashMap<>();
for (BLangAnnotationAttachment attachment : attachments) {
DefinitionID aID = new DefinitionID(attachment.annotationSymbol.pkgID.getName().value, attachment.annotationName.value);
if (!processorMap.containsKey(aID)) {
continue;
}
List<CompilerPlugin> procList = processorMap.get(aID);
procList.forEach(proc -> {
List<AnnotationAttachmentNode> attachmentNodes = attachmentMap.computeIfAbsent(proc, k -> new ArrayList<>());
attachmentNodes.add(attachment);
});
}
for (CompilerPlugin processor : attachmentMap.keySet()) {
notifier.accept(processor, Collections.unmodifiableList(attachmentMap.get(processor)));
}
}
Aggregations