Search in sources :

Example 1 with IstioVirtualServiceModel

use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.

the class IstioVirtualServiceHandler method createArtifacts.

@Override
public void createArtifacts() throws KubernetesPluginException {
    Map<String, IstioVirtualServiceModel> istioVSModels = dataHolder.getIstioVirtualServiceModels();
    int size = istioVSModels.size();
    if (size > 0) {
        OUT.println();
    }
    int count = 0;
    for (Map.Entry<String, IstioVirtualServiceModel> vsModel : istioVSModels.entrySet()) {
        count++;
        IstioGatewayModel gwModel = KubernetesContext.getInstance().getDataHolder().getIstioGatewayModel(vsModel.getKey());
        if ((null == vsModel.getValue().getGateways() || vsModel.getValue().getGateways().size() == 0) && null != gwModel) {
            if (null == vsModel.getValue().getGateways()) {
                vsModel.getValue().setGateways(new LinkedList<>());
            }
            if (vsModel.getValue().getGateways().size() == 0) {
                vsModel.getValue().getGateways().add(gwModel.getName());
            } else if (vsModel.getValue().getHosts().size() == 1 && vsModel.getValue().getHosts().contains("*")) {
                throw new KubernetesPluginException("unable to resolve a gateway for '" + vsModel + "' " + "virtual service. Add @istio:Gateway{} annotation" + " to your listener or service, else explicitly state to " + "use the 'mesh' gateway.");
            }
        }
        generate(vsModel.getKey(), vsModel.getValue());
        OUT.print("\t@istio:VirtualService \t\t\t - complete " + count + "/" + size + "\r");
    }
}
Also used : IstioGatewayModel(org.ballerinax.kubernetes.models.istio.IstioGatewayModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) IstioVirtualServiceModel(org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel) Map(java.util.Map)

Example 2 with IstioVirtualServiceModel

use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.

the class IstioVirtualServiceAnnotationProcessor method processIstioVSAnnotation.

/**
 * Process @istio:VirtualService annotation.
 *
 * @param vsFields Fields of the virtual service annotation.
 * @throws KubernetesPluginException Unable to process annotations.
 */
private IstioVirtualServiceModel processIstioVSAnnotation(List<BLangRecordLiteral.BLangRecordKeyValueField> vsFields) throws KubernetesPluginException {
    IstioVirtualServiceModel vsModel = new IstioVirtualServiceModel();
    for (BLangRecordLiteral.BLangRecordKeyValueField vsField : vsFields) {
        switch(VSConfig.valueOf(vsField.getKey().toString())) {
            case name:
                vsModel.setName(getValidName(getStringValue(vsField.getValue())));
                break;
            case labels:
                vsModel.setLabels(getMap(vsField.getValue()));
                break;
            case annotations:
                vsModel.setAnnotations(getMap(vsField.getValue()));
                break;
            case hosts:
                vsModel.setHosts(getList(vsField.getValue()));
                break;
            case gateways:
                vsModel.setGateways(getList(vsField.getValue()));
                break;
            case http:
                BLangListConstructorExpr httpFields = (BLangListConstructorExpr) vsField.getValue();
                List<IstioHttpRoute> httpModels = processHttpAnnotation(httpFields);
                vsModel.setHttp(httpModels);
                break;
            default:
                throw new KubernetesPluginException("unknown field found for istio virtual service: " + vsField.getKey().toString());
        }
    }
    return vsModel;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) IstioVirtualServiceModel(org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) IstioHttpRoute(org.ballerinax.kubernetes.models.istio.IstioHttpRoute)

Example 3 with IstioVirtualServiceModel

use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.

the class IstioVirtualServiceAnnotationProcessor method processAnnotation.

@Override
public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
    IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues);
    if (isBlank(vsModel.getName())) {
        vsModel.setName(getValidName(variableNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX);
    }
    setDefaultValues(vsModel);
    KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(variableNode.getName().getValue(), vsModel);
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) IstioVirtualServiceModel(org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel)

Example 4 with IstioVirtualServiceModel

use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.

the class IstioVirtualServiceAnnotationProcessor method processAnnotation.

@Override
public void processAnnotation(ServiceNode serviceNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
    IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues);
    if (isBlank(vsModel.getName())) {
        vsModel.setName(getValidName(serviceNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX);
    }
    setDefaultValues(vsModel);
    KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(serviceNode.getName().getValue(), vsModel);
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) IstioVirtualServiceModel(org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel)

Aggregations

IstioVirtualServiceModel (org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel)4 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)2 Map (java.util.Map)1 IstioGatewayModel (org.ballerinax.kubernetes.models.istio.IstioGatewayModel)1 IstioHttpRoute (org.ballerinax.kubernetes.models.istio.IstioHttpRoute)1 BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1