io.fabric8.openshift.api.model.ImageStreamTag Java Examples

The following examples show how to use io.fabric8.openshift.api.model.ImageStreamTag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HandlersTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void checkHandlers() {
  checkHandler(new BuildConfig(), new BuildConfigHandler());
  checkHandler(new Build(), new BuildHandler());
  checkHandler(new DeploymentConfig(), new DeploymentConfigHandler());
  checkHandler(new Group(), new GroupHandler());
  checkHandler(new Identity(), new IdentityHandler());
  checkHandler(new Image(), new ImageHandler());
  checkHandler(new ImageStream(), new ImageStreamHandler());
  checkHandler(new ImageStreamTag(), new ImageStreamTagHandler());
  checkHandler(new NetNamespace(), new NetNamespaceHandler());
  checkHandler(new OAuthAccessToken(), new OAuthAccessTokenHandler());
  checkHandler(new OAuthAuthorizeToken(), new OAuthAuthorizeTokenHandler());
  checkHandler(new OAuthClient(), new OAuthClientHandler());
  checkHandler(new Project(), new ProjectHandler());
  checkHandler(new Route(), new RouteHandler());
  checkHandler(new SecurityContextConstraints(), new SecurityContextConstraintsHandler());
  checkHandler(new User(), new UserHandler());
}
 
Example #2
Source File: ImageStreamTagExample.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

    String namespace = "myproject";
    String master = "CLUSTER_URL";
    Config config = new ConfigBuilder().withMasterUrl(master).build();
    OpenShiftClient client = new DefaultOpenShiftClient(config);

    try {

      ImageStreamTag istag = new ImageStreamTagBuilder().withNewMetadata().withName("bar1:1.0.12").endMetadata()
        .withNewTag().withNewFrom().withKind("DockerImage").withName("openshift/wildfly-81-centos7:latest").endFrom().endTag()
        .build();

      log("Created istag", client.imageStreamTags().inNamespace(namespace).create(istag));
      
      Thread.sleep(30000);

    }finally {

      log("ImageStreamTags are :");
      log(client.imageStreamTags().inNamespace(namespace).withName("bar1:1.0.12").get().toString());

      log("ImageStreamTags using list are :");
      log(client.imageStreamTags().list().getItems().get(0).toString());
      log("Deleted istag",client.imageStreamTags().withName("bar1:1.0.12").delete());
      client.close();
    }
  }
 
Example #3
Source File: S2iUtils.java    From dekorate with Apache License 2.0 4 votes vote down vote up
/**
 * Wait for the references ImageStreamTags to become available.
 * @param items       A list of items, possibly referencing image stream tags.
 * @param amount      The max amount of time to wait.
 * @param timeUnit    The time unit of the time to wait.
 * @return            True if the items became available false otherwise.
 */
public static boolean waitForImageStreamTags(Collection<HasMetadata> items, long amount, TimeUnit timeUnit) {
  if (items == null || items.isEmpty()) {
    return true;
  }
  final List<String> tags = new ArrayList<>();
  new KubernetesListBuilder()
    .withItems(new ArrayList<>(items))
    .accept(new Decorator<SourceBuildStrategyFluent>() {
        @Override
        public void visit(SourceBuildStrategyFluent strategy) {
          ObjectReference from = strategy.buildFrom();
          if (from.getKind().equals("ImageStreamTag")) {
            tags.add(from.getName());
          }
        }
      }).build();

  boolean tagsMissing = true;
  long started = System.currentTimeMillis();
  long elapsed = 0;

  while (tagsMissing && elapsed < timeUnit.toMillis(amount) && !Thread.interrupted()) {
    tagsMissing = false;
    for (String tag : tags) {
      ImageStreamTag t = client.imageStreamTags().withName(tag).get();
      if (t == null) {
        tagsMissing = true;
      }
    }

    if (tagsMissing) {
      try {
        Thread.sleep(1000);
        elapsed = System.currentTimeMillis() - started;
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }
  }
  return !tagsMissing;
}
 
Example #4
Source File: SupportUtilTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void createSupportZipFileTest() throws IOException {
    final NamespacedOpenShiftClient client = mock(NamespacedOpenShiftClient.class);

    final MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods = mock(mixedOperationType());
    when(pods.list()).thenReturn(new PodList());

    when(client.pods()).thenReturn(pods);

    final MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> bcs = mock(
        mixedOperationType());
    when(bcs.list()).thenReturn(new BuildConfigList());

    when(client.buildConfigs()).thenReturn(bcs);

    final MixedOperation<DeploymentConfig, DeploymentConfigList, DoneableDeploymentConfig, DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig>> dcs = mock(
        mixedOperationType());
    when(dcs.list()).thenReturn(new DeploymentConfigList());

    when(client.deploymentConfigs()).thenReturn(dcs);

    final MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> cm = mock(mixedOperationType());
    when(cm.list()).thenReturn(new ConfigMapList());

    when(client.configMaps()).thenReturn(cm);

    final MixedOperation<ImageStreamTag, ImageStreamTagList, DoneableImageStreamTag, Resource<ImageStreamTag, DoneableImageStreamTag>> ist = mock(
        mixedOperationType());
    final ImageStreamTagList istl = new ImageStreamTagList();
    final List<ImageStreamTag> istList = new ArrayList<>();
    final ImageStreamTag imageStreamTag = new ImageStreamTag();
    imageStreamTag.setKind("ImageStreamTag");
    final ObjectMeta objectMeta = new ObjectMeta();
    objectMeta.setName("ImageStreamTag1");
    imageStreamTag.setMetadata(objectMeta);
    istList.add(imageStreamTag);
    istl.setItems(istList);

    when(ist.list()).thenReturn(istl);

    when(client.imageStreamTags()).thenReturn(ist);

    final IntegrationHandler integrationHandler = mock(IntegrationHandler.class);
    when(integrationHandler.list(anyInt(), anyInt())).thenReturn(new EmptyListResult<IntegrationOverview>());
    final IntegrationSupportHandler integrationSupportHandler = mock(IntegrationSupportHandler.class);

    final Logger log = mock(Logger.class);
    final SupportUtil supportUtil = new SupportUtil(client, integrationHandler, integrationSupportHandler, log);

    final Map<String, Boolean> configurationMap = new HashMap<>(ImmutableMap.of("int1", true, "int2", true));

    final File output = supportUtil.createSupportZipFile(configurationMap, 1, 20);

    try (final ZipFile zip = new ZipFile(output)) {
        final ZipEntry imageStreamTag1 = zip.getEntry("descriptors/ImageStreamTag/ImageStreamTag1.YAML");
        assertThat(imageStreamTag1).isNotNull();
        AssertionsForClassTypes.assertThat(zip.getInputStream(imageStreamTag1)).hasContent(SupportUtil.YAML.dump(imageStreamTag));
    }

    verify(log).info("Created Support file: {}", output);
    // tests that we haven't logged any error messages
    verifyZeroInteractions(log);
}
 
Example #5
Source File: ImageStreamTagCrudTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void crudTest() {

  OpenShiftClient client = openshiftServer.getOpenshiftClient();

  logger.info("Current User " + client.currentUser());

  ImageStreamTag istag = new ImageStreamTagBuilder().withNewMetadata().withName("bar1:1.0.12").endMetadata()
    .withNewTag()
      .withNewFrom()
        .withKind("DockerImage")
        .withName("openshift/wildfly-81-centos7:latest")
      .endFrom()
      .withReference(false)
    .endTag()
    .withGeneration(1L)
    .build();

  //test of Creation
  istag = client.imageStreamTags().create(istag);

  assertNotNull(istag);
  assertEquals("bar1:1.0.12", istag.getMetadata().getName());
  assertEquals("DockerImage", istag.getTag().getFrom().getKind());
  assertEquals("openshift/wildfly-81-centos7:latest", istag.getTag().getFrom().getName());
  assertEquals(false, istag.getTag().getReference());
  assertEquals(1, istag.getGeneration().intValue());

  //test of List
  ImageStreamTagList istagList = client.imageStreamTags().list();

  logger.info(istagList.toString());
  assertNotNull(istagList);
  assertEquals(1,istagList.getItems().size());
  assertEquals("bar1:1.0.12", istagList.getItems().get(0).getMetadata().getName());
  assertEquals("DockerImage", istagList.getItems().get(0).getTag().getFrom().getKind());
  assertEquals("openshift/wildfly-81-centos7:latest", istagList.getItems().get(0).getTag().getFrom().getName());
  assertEquals(false, istagList.getItems().get(0).getTag().getReference());
  assertEquals(1, istagList.getItems().get(0).getGeneration().intValue());

  //test of Updation
  ImageStreamTag istag2 = new ImageStreamTagBuilder().withNewMetadata().withName("bar1:1.0.12").endMetadata()
    .withNewTag()
    .withNewFrom()
    .withKind("DockerImage")
    .withName("openshift/wildfly-81-centos7:latest")
    .endFrom()
    .withReference(false)
    .endTag()
    .withGeneration(2L)
    .build();

  istag = client.imageStreamTags().withName("bar1:1.0.12").patch(istag2);
  logger.info(istag.toString());

  assertNotNull(istag);
  assertEquals("bar1:1.0.12", istag.getMetadata().getName());
  assertEquals("DockerImage", istag.getTag().getFrom().getKind());
  assertEquals("openshift/wildfly-81-centos7:latest", istag.getTag().getFrom().getName());
  assertEquals(false, istag.getTag().getReference());
  assertEquals(2, istag.getGeneration().intValue());

  boolean deleted = client.imageStreamTags().withName("bar1:1.0.12").delete();
  assertTrue(deleted);
  istagList = client.imageStreamTags().list();
  assertEquals(0, istagList.getItems().size());
}
 
Example #6
Source File: DefaultOpenShiftClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<ImageStreamTag, ImageStreamTagList, DoneableImageStreamTag, Resource<ImageStreamTag, DoneableImageStreamTag>> imageStreamTags() {
  return new ImageStreamTagOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration()));
}