AtomicBoolean hasError = new AtomicBoolean(false); for (Pod pod : pods.items) { PodState podState = new PodState(); podState.pod = pod; podState.name = pod.metadata.name;
@Test public void testCreateKubernetesEntityDescription() { final String testKey = "testKey"; final String testValue = "testValue"; PodState podState = new PodState(); podState.descriptionLink = "/test/description-" + UUID.randomUUID().toString(); podState.tenantLinks = Collections.singletonList("/tenants/test-tenant"); podState.name = UUID.randomUUID().toString(); podState.id = UUID.randomUUID().toString(); podState.customProperties = new HashMap<>(); podState.customProperties.put(testKey, testValue); KubernetesDescription podDescription = KubernetesUtil .createKubernetesEntityDescription(podState); assertThat(podDescription.documentSelfLink, is(podState.descriptionLink)); assertThat(podDescription.name, is(podState.name)); assertThat(podDescription.id, is(podState.id)); assertThat(podDescription.type, is(podState.getType())); assertThat(podDescription.tenantLinks, is(podState.tenantLinks)); assertThat(podDescription.customProperties, is(notNullValue())); assertThat(podDescription.customProperties.get(testKey), is(testValue)); assertEquals(podState.name, podDescription.name); }
case POD_TYPE: Pod pod = response.getBody(Pod.class); PodState podState = new PodState(); podState.pod = pod; podState.name = pod.metadata.name;
ArrayList<Pair<String, BaseKubernetesState>> entities = new ArrayList<>(); entities.add(new Pair<>(PodFactoryService.SELF_LINK, new PodService.PodState())); entities.add(new Pair<>(DeploymentFactoryService.SELF_LINK, new DeploymentService.DeploymentState())); PodService.PodState state = new PodService.PodState(); state.pod = new Pod(); state.pod.spec = new PodSpec();
@Test public void testDiscoveredEntitiesWillNotDuplicateExisting() throws Throwable { BaseKubernetesState pod = new PodState(); pod.id = "pod-1"; pod.name = "my_prog_1"; KubernetesUtil.REPLICATION_CONTROLLER_TYPE, null)); PodState existingPod = new PodState(); existingPod.id = pod.id; existingPod.name = pod.name + "_second";
service.containerNamesToLogs.put("container3", "test-log-3"); PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec();
@Test public void testInspect() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec();
@Test public void testDelete() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec();
private PodState createPodState() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); container1.name = "container1"; Container container2 = new Container(); container2.name = "container2"; Container container3 = new Container(); container3.name = "container3"; Container container4 = new Container(); container4.name = "container4"; Container container5 = new Container(); container5.name = "container5"; Container container6 = new Container(); container6.name = "container6"; podState.pod.spec.containers.add(container1); podState.pod.spec.containers.add(container2); podState.pod.spec.containers.add(container3); podState.pod.spec.containers.add(container4); podState.pod.spec.containers.add(container5); podState.pod.spec.containers.add(container6); podState.pod.metadata = new ObjectMeta(); podState.pod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; podState.pod.metadata.uid = UUID.randomUUID().toString(); podState.documentSelfLink = podState.pod.metadata.uid; podState = doPost(podState, PodFactoryService.SELF_LINK); return podState; }
@Test public void testRequestBrokerContainerHostRemovalWithKubernetesResources() throws Throwable { computeHost.customProperties.put(ContainerHostService.CONTAINER_HOST_TYPE_PROP_NAME, ContainerHostType.KUBERNETES.name()); computeHost = doPatch(computeHost, computeHost.documentSelfLink); PodState podState = new PodState(); podState.parentLink = computeHost.documentSelfLink; podState = doPost(podState, PodFactoryService.SELF_LINK); ServiceState serviceState = new ServiceState(); serviceState.parentLink = computeHost.documentSelfLink; serviceState = doPost(serviceState, ServiceEntityFactoryHandler.SELF_LINK); RequestBrokerState request = new RequestBrokerState(); request.resourceType = ResourceType.CONTAINER_HOST_TYPE.getName(); request.resourceLinks = new HashSet<>(Collections.singletonList( computeHost.documentSelfLink)); request.operation = RequestBrokerState.REMOVE_RESOURCE_OPERATION; request = startRequest(request); waitForRequestToComplete(request); List<String> podStateLinks = findResourceLinks(PodState.class, Collections.singletonList(podState.documentSelfLink)); assertTrue("PodState links not removed: " + podStateLinks, podStateLinks.isEmpty()); List<String> serviceStateLinks = findResourceLinks(ServiceState.class, Collections.singletonList(serviceState.documentSelfLink)); assertTrue("ServiceState links not removed: " + serviceStateLinks, serviceStateLinks.isEmpty()); Collection<String> computeSelfLinks = findResourceLinks(ComputeState.class, Collections.singletonList(computeHost.documentSelfLink)); assertTrue("ComputeState was not deleted: " + computeSelfLinks, computeSelfLinks.isEmpty()); }
@Test public void testDataCollectionDeleteMissingState() throws Throwable { BaseKubernetesState pod = new PodState(); pod.id = "pod-1"; pod.name = "my_prog_1"; PodState existingPod = new PodState(); existingPod.id = pod.id; existingPod.name = pod.name + "_second"; existingPod.parentLink = COMPUTE_HOST_LINK; existingPod.documentSelfLink = existingPod.id; host.testStart(1); host.sendRequest( Operation.createPost(UriUtils.buildUri(host, PodFactoryService.SELF_LINK)) .setBody(existingPod) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { host.failIteration(ex); } else { addForDelete(o.getBody(ResourceState.class).documentSelfLink); host.completeIteration(); } })); host.testWait(); startDataCollectionAndWait(); List<PodState> pods = getEntities(PodState.class); Assert.assertEquals(0, pods.size()); }
@Test public void testAdapterRequestOnPeriodicMaintenance() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); container1.name = "container1"; container1.image = "test-image"; podState.pod.spec.containers.add(container1); podState.pod.metadata = new ObjectMeta(); podState.pod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; podState.pod.metadata.name = "test-pod"; podState = doPost(podState, PodFactoryService.SELF_LINK); waitFor(() -> MockKubernetesAdapterService.requestOnInspect != null); assertNotNull(MockKubernetesAdapterService.requestOnInspect); assertEquals(KubernetesOperationType.INSPECT.id, MockKubernetesAdapterService .requestOnInspect.operationTypeId); assertEquals(podState.documentSelfLink, MockKubernetesAdapterService.requestOnInspect .resourceReference.getPath()); }
@Test public void testCreate() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); podState.pod.spec.containers.add(container1); podState.pod.metadata = new ObjectMeta(); podState.pod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; podState.parentLink = kubernetesHostState.documentSelfLink; podState = doPost(podState, PodFactoryService.SELF_LINK); provisioningTaskLink = createProvisioningTask(); AdapterRequest request = new AdapterRequest(); request.resourceReference = UriUtils.buildUri(host, podState.documentSelfLink); request.serviceTaskCallback = ServiceTaskCallback.create(provisioningTaskLink); request.operationTypeId = KubernetesOperationType.CREATE.id; doOperation(KubernetesAdapterService.SELF_LINK, request); waitForPropertyValue(provisioningTaskLink, MockTaskState.class, "taskInfo.stage", TaskState.TaskStage.FAILED); }
public static BaseKubernetesState createKubernetesEntityState(String kind) { switch (kind) { case KubernetesUtil.POD_TYPE: return new PodState(); case KubernetesUtil.SERVICE_TYPE: return new ServiceState(); case KubernetesUtil.DEPLOYMENT_TYPE: return new DeploymentState(); case KubernetesUtil.REPLICATION_CONTROLLER_TYPE: return new ReplicationControllerState(); case KubernetesUtil.REPLICA_SET_TYPE: return new ReplicaSetState(); default: return new GenericKubernetesEntityState(); } }
@Test public void testDiscoverSingleEntity() throws Throwable { BaseKubernetesState entity = new PodState(); entity.name = "entity"; entity.id = "id"; MockKubernetesAdapterService .addEntity(makeEntity(entity.id, entity.name, KubernetesUtil.POD_TYPE, null)); startDataCollectionAndWait(); List<PodState> entities = getEntities(PodState.class); Assert.assertEquals(1, entities.size()); Assert.assertEquals(entity.id, entities.get(0).id); Assert.assertEquals(entity.name, entities.get(0).name); }
private PodState createPod(CompositeComponent composite) throws Throwable { PodState pod = new PodState(); pod.compositeComponentLink = composite.documentSelfLink; pod = doPost(pod, PodFactoryService.SELF_LINK); addForDeletion(pod); return pod; }
@Test public void testBuildLogUriPath() { String uuid = UUID.randomUUID().toString(); String containerName = "pod1"; BaseKubernetesState state = new PodState(); state.documentSelfLink = PodFactoryService.SELF_LINK + "/" + uuid; String expectedPath = String.format("/logs/%s-%s", uuid, containerName); assertEquals(expectedPath, KubernetesUtil.buildLogUriPath(state, containerName)); }