private ConfigMap create(AddressSpace addressSpace) { Map<String, String> labels = addressSpace.getMetadata().getLabels(); if ( labels == null ) { labels = new HashMap<>(); addressSpace.getMetadata().setLabels(labels); } String name = getConfigMapName(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName()); labels.put(LabelKeys.TYPE, "address-space"); labels.put(LabelKeys.NAMESPACE, addressSpace.getMetadata().getNamespace()); ConfigMapBuilder builder = new ConfigMapBuilder() .editOrNewMetadata() .withName(name) .addToLabels(labels) .addToAnnotations(addressSpace.getMetadata().getAnnotations()) .endMetadata(); if (addressSpace.getMetadata().getResourceVersion() != null) { builder.editOrNewMetadata() .withResourceVersion(addressSpace.getMetadata().getResourceVersion()) .endMetadata(); } try { // Reset resource version to avoid unneeded extra writes AddressSpace newAddressSpace = new AddressSpaceBuilder(addressSpace).editOrNewMetadata().withResourceVersion(null).endMetadata().build(); builder.addToData("config.json", mapper.writeValueAsString(newAddressSpace)); return builder.build(); } catch (IOException e) { log.info("Error serializing addressspace for {}", addressSpace, e); throw new UncheckedIOException(e); } }
.withNamespace(addressSpace.getMetadata().getNamespace()) .withName(addressSpace.getMetadata().getName() + "." + username) .endMetadata()
private AddressSpace getAddressSpaceFromConfig(ConfigMap map) { try { AddressSpace addressSpace = mapper.readValue(map.getData().get("config.json"), AddressSpace.class); AddressSpaceBuilder builder = new AddressSpaceBuilder(addressSpace); MetadataNested<AddressSpaceBuilder> metadataBuilder = builder.editOrNewMetadata(); if (addressSpace.getMetadata().getUid() == null) { metadataBuilder.withUid(map.getMetadata().getUid()); } metadataBuilder.withResourceVersion(map.getMetadata().getResourceVersion()); if (addressSpace.getMetadata().getCreationTimestamp() == null) { metadataBuilder.withCreationTimestamp(map.getMetadata().getCreationTimestamp()); } if (addressSpace.getMetadata().getSelfLink() == null) { metadataBuilder.withSelfLink("/apis/enmasse.io/v1beta1/namespaces/" + addressSpace.getMetadata().getNamespace() + "/addressspaces/" + addressSpace.getMetadata().getName()); } // commit changes metadataBuilder.endMetadata(); return builder.build(); } catch (IOException e) { log.error("Error decoding address space from configmap : {}", map, e); throw new UncheckedIOException(e); } }
.withAnnotations(annotations) .withLabels(labels) .endMetadata()
AddressBuilder builder = new AddressBuilder(address); if (address.getMetadata().getNamespace() == null) { builder.editOrNewMetadata().withNamespace(namespace).endMetadata(); builder.editOrNewMetadata().withName(Address.generateName(addressSpace, address.getSpec().getAddress())).endMetadata(); .addToAnnotations(address.getMetadata().getAnnotations()) .addToLabels(address.getMetadata().getLabels()) .endMetadata()
private ConfigMap create(Address address) { ConfigMapBuilder builder = new ConfigMapBuilder() .editOrNewMetadata() .withName(getConfigMapName(address.getMetadata().getNamespace(), address.getMetadata().getName())) .addToLabels(address.getMetadata().getLabels()) .addToLabels(LabelKeys.TYPE, "address-config") .addToLabels(LabelKeys.INFRA_UUID, infraUuid) .addToLabels(LabelKeys.INFRA_TYPE, "any") .addToAnnotations(address.getMetadata().getAnnotations()) // TODO: Support other ways of doing this .addToAnnotations(AnnotationKeys.ADDRESS_SPACE, Address.extractAddressSpace(address)) .endMetadata(); if (address.getMetadata().getResourceVersion() != null) { builder.editOrNewMetadata() .withResourceVersion(address.getMetadata().getResourceVersion()) .endMetadata(); } try { // Reset resource version to avoid unneeded extra writes final Address newAddress = new AddressBuilder(address).editOrNewMetadata().withResourceVersion(null).endMetadata().build(); builder.addToData("config.json", mapper.writeValueAsString(newAddress)); return builder.build(); } catch (IOException e) { log.info("Error serializing address for {}", address, e); throw new UncheckedIOException(e); } }
private Address getAddressFromConfig(ConfigMap map) { Map<String, String> data = map.getData(); try { Address address = mapper.readValue(data.get("config.json"), Address.class); AddressBuilder builder = new AddressBuilder(address); MetadataNested<AddressBuilder> metadataBuilder = builder.editOrNewMetadata(); if (address.getMetadata().getUid() == null) { metadataBuilder.withUid(map.getMetadata().getUid()); } metadataBuilder.withResourceVersion(map.getMetadata().getResourceVersion()); if (address.getMetadata().getCreationTimestamp() == null) { metadataBuilder.withCreationTimestamp(map.getMetadata().getCreationTimestamp()); } if (address.getMetadata().getSelfLink() == null) { metadataBuilder.withSelfLink("/apis/enmasse.io/v1beta1/namespaces/" + address.getMetadata().getNamespace() + "/addressspaces/" + Address.extractAddressSpace(address)); } // commit changes to metadata metadataBuilder.endMetadata(); return builder.build(); } catch (IOException e) { log.error("Error decoding address from configmap : {}", map, e); throw new UncheckedIOException(e); } }
protected AddressSpace createAddressSpace(String instanceId, String name, String type, String plan, String userId, String userName) throws Exception { AuthenticationService authService = new AuthenticationServiceBuilder() .withType(AuthenticationServiceType.STANDARD) .withDetails(Collections.emptyMap()) .build(); AddressSpace addressSpace = new AddressSpaceBuilder() .withNewMetadata() .withName(name) .addToAnnotations(AnnotationKeys.CREATED_BY, userName) .addToAnnotations(AnnotationKeys.CREATED_BY_UID, userId) .addToLabels(LabelKeys.SERVICE_INSTANCE_ID, instanceId) .endMetadata() .withNewSpec() .withType(type) .withPlan(plan) .withAuthenticationService(authService) .endSpec() .build(); addressSpace = setDefaults(addressSpace, namespace); addressSpaceApi.createAddressSpace(addressSpace); log.info("Created MaaS addressspace {}", addressSpace.getMetadata().getName()); return addressSpace; }
private AddressSpace setDefaults(AddressSpace addressSpace, String namespace) { if (addressSpace.getMetadata().getNamespace() == null) { addressSpace = new AddressSpaceBuilder(addressSpace) .editOrNewMetadata() .withNamespace(namespace) .endMetadata() .build(); } final Map<String, String> annotations = addressSpace.getMetadata().getAnnotations(); final Map<String, String> labels = addressSpace.getMetadata().getLabels(); annotations.putIfAbsent(AnnotationKeys.REALM_NAME, KubeUtil.sanitizeName(addressSpace.getMetadata().getNamespace() + "-" + addressSpace.getMetadata().getName())); annotations.putIfAbsent(AnnotationKeys.INFRA_UUID, uuidGenerator.generateInfraUuid()); labels.putIfAbsent(LabelKeys.ADDRESS_SPACE_TYPE, addressSpace.getSpec().getType()); labels.putIfAbsent(LabelKeys.NAMESPACE, addressSpace.getMetadata().getNamespace()); return addressSpace; }
public static AddressSpaceSchema fromAddressSpaceType(final String creationTimestamp, final AddressSpaceType addressSpaceType) { if (addressSpaceType == null) { return null; } return new AddressSpaceSchemaBuilder() .withNewMetadata() .withName(addressSpaceType.getName()) .withCreationTimestamp(creationTimestamp) .endMetadata() .withSpec(AddressSpaceSchemaSpec.fromAddressSpaceType(addressSpaceType)) .build(); }