Search in sources :

Example 1 with ObjectReference

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference in project open-smart-grid-platform by OSGP.

the class DeviceConnection method getFcModelNode.

/**
 * Returns a {@link NodeContainer} for the given {@link ObjectReference} data and the Functional
 * constraint.
 *
 * @throws NodeNotFoundException
 */
public NodeContainer getFcModelNode(final LogicalDevice logicalDevice, final LogicalNode logicalNode, final DataAttribute dataAttribute, final Fc fc) throws NodeNotFoundException {
    final ObjectReference objectReference = this.createObjectReference(logicalDevice, logicalNode, dataAttribute);
    final FcModelNode fcModelNode = (FcModelNode) this.connection.getServerModel().findModelNode(objectReference, fc);
    if (fcModelNode == null) {
        LOGGER.error("FcModelNode is null, most likely the data attribute: {} does not exist", dataAttribute.getDescription());
        throw new NodeNotFoundException(String.format("FcModelNode with objectReference %s does not exist", objectReference));
    }
    return new NodeContainer(this, fcModelNode);
}
Also used : NodeNotFoundException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeNotFoundException) ObjectReference(com.beanit.openiec61850.ObjectReference) FcModelNode(com.beanit.openiec61850.FcModelNode)

Example 2 with ObjectReference

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference in project open-smart-grid-platform by OSGP.

the class DeviceConnection method getFcModelNode.

/**
 * Returns a {@link NodeContainer} for the given {@link ObjectReference} data and the Functional
 * constraint.
 *
 * @throws NodeNotFoundException
 */
public NodeContainer getFcModelNode(final LogicalDevice logicalDevice, final int logicalDeviceIndex, final LogicalNode logicalNode, final DataAttribute dataAttribute, final Fc fc) throws NodeNotFoundException {
    final ObjectReference objectReference = this.createObjectReference(logicalDevice, logicalDeviceIndex, logicalNode, dataAttribute);
    final FcModelNode fcModelNode = (FcModelNode) this.connection.getServerModel().findModelNode(objectReference, fc);
    if (fcModelNode == null) {
        LOGGER.error("FcModelNode is null, most likely the data attribute: {} does not exist", dataAttribute.getDescription());
        throw new NodeNotFoundException(String.format("FcModelNode with objectReference %s does not exist", objectReference));
    }
    return new NodeContainer(this, fcModelNode);
}
Also used : NodeNotFoundException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeNotFoundException) ObjectReference(com.beanit.openiec61850.ObjectReference) FcModelNode(com.beanit.openiec61850.FcModelNode)

Example 3 with ObjectReference

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference in project yakc by manusa.

the class AuthIT method retrieveSecretForServiceAccount.

private Secret retrieveSecretForServiceAccount() throws IOException {
    final ServiceAccount sa = KC.create(CoreV1Api.class).listNamespacedServiceAccount(NAMESPACE).stream().findFirst().orElseThrow(() -> new AssertionError("No Service Account found"));
    final String secretName = sa.getSecrets() == null ? null : sa.getSecrets().stream().findFirst().map(ObjectReference::getName).orElse(null);
    if (secretName != null) {
        return KC.create(CoreV1Api.class).listNamespacedSecret(NAMESPACE).stream().filter(s -> s.getType().equals("kubernetes.io/service-account-token")).filter(s -> s.getMetadata().getName().equals(secretName)).findAny().orElseThrow(() -> new AssertionError(String.format("Secret %s doesn't exist", secretName)));
    } else {
        // https://kubernetes.io/docs/concepts/configuration/secret/#service-account-token-secrets
        final Secret serviceAccountTokenSecret = Secret.builder().metadata(ObjectMeta.builder().name(sa.getMetadata().getName() + "-token").putInAnnotations("kubernetes.io/service-account.name", sa.getMetadata().getName()).build()).type("kubernetes.io/service-account-token").putInStringData("token", "my-secret-token").build();
        return KC.create(CoreV1Api.class).createNamespacedSecret(NAMESPACE, serviceAccountTokenSecret).get();
    }
}
Also used : Node(com.marcnuri.yakc.model.io.k8s.api.core.v1.Node) KC(com.marcnuri.yakc.KubernetesClientExtension.KC) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceAccount(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount) IOException(java.io.IOException) Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) Test(org.junit.jupiter.api.Test) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) ObjectMeta(com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta) Configuration(com.marcnuri.yakc.config.Configuration) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) ObjectReference(com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference) Secret(com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret) ServiceAccount(com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount) ObjectReference(com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference)

Aggregations

FcModelNode (com.beanit.openiec61850.FcModelNode)2 ObjectReference (com.beanit.openiec61850.ObjectReference)2 NodeNotFoundException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeNotFoundException)2 KC (com.marcnuri.yakc.KubernetesClientExtension.KC)1 CoreV1Api (com.marcnuri.yakc.api.core.v1.CoreV1Api)1 Configuration (com.marcnuri.yakc.config.Configuration)1 Node (com.marcnuri.yakc.model.io.k8s.api.core.v1.Node)1 ObjectReference (com.marcnuri.yakc.model.io.k8s.api.core.v1.ObjectReference)1 Secret (com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret)1 ServiceAccount (com.marcnuri.yakc.model.io.k8s.api.core.v1.ServiceAccount)1 ObjectMeta (com.marcnuri.yakc.model.io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta)1 IOException (java.io.IOException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1