• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Image类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.github.dockerjava.api.model.Image的典型用法代码示例。如果您正苦于以下问题:Java Image类的具体用法?Java Image怎么用?Java Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Image类属于com.github.dockerjava.api.model包,在下文中一共展示了Image类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: serviceDiskUsage

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
public String serviceDiskUsage ( ServiceInstance service ) {
	long resultInMb = 0;
	try {

		Optional<Image> match = findImageByName( service.getDockerImageName() );

		if ( match.isPresent() ) {

			InspectImageResponse info = dockerClient.inspectImageCmd( match.get().getId() ).exec();
			resultInMb = info.getSize();
			logger.debug( "resultInMb: {} bytes", resultInMb );
			resultInMb = resultInMb / CSAP.MB_FROM_BYTES;
		} else {
			resultInMb = 1;
		}

	} catch (Exception e) {
		String reason = CSAP.getCsapFilteredStackTrace( e );
		logger.warn( "Failed finding size {}, {}", service.getDockerImageName(), reason );
	}

	String duMessage = resultInMb + "M " + service.getServiceName_Port();

	logger.debug( duMessage );
	return duMessage;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:27,代码来源:DockerHelper.java


示例2: findImageByName

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
public Optional<Image> findImageByName ( String name ) {
	List<Image> images = dockerClient.listImagesCmd().exec();

	Optional<Image> matchImage = images
		.stream()
		.filter( image -> {
			boolean foundMatch = false;
			
			if ( image.getRepoTags() != null ) {
				foundMatch = Arrays.asList( image.getRepoTags() ).contains( name ) ;
			}
			// Arrays.asList( image.getRepoTags() ).contains( name )
			return foundMatch ;
		})
		.findFirst();
	return matchImage;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:18,代码来源:DockerHelper.java


示例3: ensureImage

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
public static void ensureImage(String imageName) {
    List<Image> images = dockerClient.listImagesCmd().withImageNameFilter(imageName).exec();
    if (images.isEmpty()){
        logger.info("Pulling docker image from Docker Hub ...");
        // FIXME: Figure out how image tags should work
        dockerClient.pullImageCmd(imageName).withTag("latest")
                .exec(new PullImageResultCallback(){
                    @Override
                    public void onNext(PullResponseItem item) {
                        super.onNext(item);
                        logger.debug(item.toString());
                    }
                })
                .awaitSuccess();
        logger.info("Finished pulling docker image.");
    }
}
 
开发者ID:b-long,项目名称:jedi,代码行数:18,代码来源:ContainerUtils.java


示例4: getUnusedDockerImages

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
/**
 * Generates lists of images that are safe to delete, in the order that is safe to delete them (children before
 * parents). The function starts with the set of all local images and then filters out images that are used now
 * and images that have been used recently (because they might be re-used again in near future).
 *
 * @param images List of all the local images
 * @param containers List of all the containers, including the ones that are stopped
 * @return List of image tags of unused images, if unused image has no tag, will return image ID instead.
 */
public List<DockerImage> getUnusedDockerImages(List<Image> images, List<Container> containers) {
    Map<String, Image> dockerImageByImageId = images.stream().collect(Collectors.toMap(Image::getId, img -> img));
    Map<String, Image> unusedImagesByContainers = filterOutImagesUsedByContainers(dockerImageByImageId, containers);
    Map<String, Image> unusedImagesByRecent = filterOutRecentImages(unusedImagesByContainers);

    return unusedImagesByRecent.keySet().stream()
            .sorted((o1, o2) -> {
                // If image2 is parent of image1, image1 comes before image2
                if (imageIsDescendantOf(unusedImagesByRecent, o1, o2)) return -1;
                // If image1 is parent of image2, image2 comes before image1
                else if (imageIsDescendantOf(unusedImagesByRecent, o2, o1)) return 1;
                // Otherwise, sort lexicographically by image name (For testing)
                else return o1.compareTo(o2);
            })
            .flatMap(imageId -> {
                // Deleting an image by image ID with multiple tags will fail -> map IDs to all the tags refering to the ID
                String[] repoTags = unusedImagesByRecent.get(imageId).getRepoTags();
                return (repoTags == null) ? Stream.of(imageId) : Stream.of(repoTags);
            })
            .map(DockerImage::new)
            .collect(Collectors.toList());
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:32,代码来源:DockerImageGarbageCollector.java


示例5: filterOutImagesUsedByContainers

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
private Map<String, Image> filterOutImagesUsedByContainers(
        Map<String, Image> dockerImagesByImageId, List<com.github.dockerjava.api.model.Container> containerList) {
    Map<String, Image> filteredDockerImagesByImageId = new HashMap<>(dockerImagesByImageId);

    for (com.github.dockerjava.api.model.Container container : containerList) {
        String imageToSpare = container.getImageId();
        do {
            // May be null if two images have have the same parent, the first image will remove the parent, the
            // second will get null.
            Image sparedImage = filteredDockerImagesByImageId.remove(imageToSpare);
            imageToSpare = sparedImage == null ? "" : sparedImage.getParentId();
        } while (!imageToSpare.isEmpty());
    }

    return filteredDockerImagesByImageId;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:17,代码来源:DockerImageGarbageCollector.java


示例6: filterOutRecentImages

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
private Map<String, Image> filterOutRecentImages(Map<String, Image> dockerImageByImageId) {
    Map<String, Image> filteredDockerImagesByImageId = new HashMap<>(dockerImageByImageId);

    final Instant now = Instant.now();
    filteredDockerImagesByImageId.keySet().forEach(imageId -> {
        if (! lastTimeUsedByImageId.containsKey(imageId)) lastTimeUsedByImageId.put(imageId, now);
    });

    lastTimeUsedByImageId.entrySet().stream()
            .filter(entry -> Duration.between(entry.getValue(), now).minus(MIN_AGE_IMAGE_GC).isNegative())
            .map(Map.Entry::getKey)
            .forEach(image -> {
                String imageToSpare = image;
                do {
                    Image sparedImage = filteredDockerImagesByImageId.remove(imageToSpare);
                    imageToSpare = sparedImage == null ? "" : sparedImage.getParentId();
                } while (!imageToSpare.isEmpty());
            });
    return filteredDockerImagesByImageId;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:21,代码来源:DockerImageGarbageCollector.java


示例7: imageExists

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
protected Boolean imageExists(String imageName, String registryTag) {
    List<Image> images = DockerClientFactory.build().listImagesCmd().exec();
    if (images.isEmpty()) {
        throw new MinimesosException("Failed to find image '" +  imageName + ":" + registryTag + ". No images found");
    }
    for (Image image : images) {
        if (image.getRepoTags() == null) {
            continue;
        }
        for (String repoTag : image.getRepoTags()) {
            if (repoTag.equals(imageName + ":" + registryTag)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:ContainerSolutions,项目名称:minimesos,代码行数:18,代码来源:AbstractContainer.java


示例8: findImageByIdOrByTag

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
/**
 * Finds an image by ID or by tag.
 * @param name an image ID or a tag name (can be null)
 * @param dockerClient a Docker client (not null)
 * @return an image, or null if none matched
 */
public static Image findImageByIdOrByTag( String name, DockerClient dockerClient ) {

	Image image = null;
	if( ! Utils.isEmptyOrWhitespaces( name )) {
		Logger logger = Logger.getLogger( DockerUtils.class.getName());

		List<Image> images = dockerClient.listImagesCmd().exec();
		if(( image = DockerUtils.findImageById( name, images )) != null )
			logger.fine( "Found a Docker image with ID " + name );
		else if(( image = DockerUtils.findImageByTag( name, images )) != null )
			logger.fine( "Found a Docker image with tag " + name );
	}

	return image;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:22,代码来源:DockerUtils.java


示例9: findImageByTag

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
/**
 * Finds an image by tag.
 * @param imageTag the image tag (not null)
 * @param images a non-null list of images
 * @return an image, or null if none was found
 */
public static Image findImageByTag( String imageTag, List<Image> images ) {

	Image result = null;
	for( Image img : images ) {
		String[] tags = img.getRepoTags();
		if( tags == null )
			continue;

		for( String s : tags ) {
			if( s.contains( imageTag )) {
				result = img;
				break;
			}
		}
	}

	return result;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:25,代码来源:DockerUtils.java


示例10: configure

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@Override
public boolean configure() throws TargetException {

	// Creating a container is almost immediate.
	// And building an image with the REST API is blocking the thread until the creation is complete.
	// So, this is not asynchronous configuration.
	// Said differently, this method will be invoked only once!

	Map<String,String> targetProperties = this.parameters.getTargetProperties();
	this.dockerClient = DockerUtils.createDockerClient( targetProperties );

	String rbcfVersion = DockerUtils.findDefaultImageVersion( ManifestUtils.findBundleVersion());
	String imageId = Utils.getValue( targetProperties, IMAGE_ID, DEFAULT_IMAGE + ":" + rbcfVersion );
	this.logger.fine( "Used image: " + imageId );

	Image img = DockerUtils.findImageByIdOrByTag( imageId, this.dockerClient );
	if( img == null )
		createImage( imageId );

	createContainer( imageId );
	return true;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:23,代码来源:DockerMachineConfigurator.java


示例11: testDockerUtils_onLimits

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@Test
public void testDockerUtils_onLimits() {

	DockerUtils.deleteImageIfItExists( null, this.docker );
	Assert.assertTrue( "No exception is thrown trying to delete a null image ID.", true );

	DockerUtils.deleteImageIfItExists( "bla 11 4 2 bla", this.docker );
	Assert.assertTrue( "No exception is thrown trying to delete something that does not exist.", true );

	Container container = DockerUtils.findContainerByIdOrByName( "bla 11 4 2 bla", this.docker );
	Assert.assertNull( container );

	Image image = DockerUtils.findImageByIdOrByTag( null, this.docker );
	Assert.assertNull( image );

	image = DockerUtils.findImageByIdOrByTag( "invalid", this.docker );
	Assert.assertNull( image );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:19,代码来源:DockerHandlerWithContainerTest.java


示例12: execute

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@Override
protected List<Image> execute(ListImagesCmd command) {
    WebTarget webTarget = getBaseResource().path("/images/json");

    webTarget = booleanQueryParam(webTarget, "all", command.hasShowAllEnabled());

    if (command.getFilters() != null && !command.getFilters().isEmpty()) {
        webTarget = webTarget.queryParam("filters", urlPathSegmentEscaper().escape(FiltersEncoder.jsonEncode(command.getFilters())));
    }

    if (command.getImageNameFilter() != null) {
        webTarget = webTarget.queryParam("filter", urlPathSegmentEscaper().escape(command.getImageNameFilter()));
    }

    LOGGER.trace("GET: {}", webTarget);

    List<Image> images = webTarget.request().accept(MediaType.APPLICATION_JSON).get(new GenericType<List<Image>>() {
    });
    LOGGER.trace("Response: {}", images);

    return images;
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:23,代码来源:ListImagesCmdExec.java


示例13: execute

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@Override
protected List<Image> execute(ListImagesCmd command) {
    WebTarget webTarget = getBaseResource().path("/images/json");

    webTarget = booleanQueryParam(webTarget, "all", command.hasShowAllEnabled());

    if (command.getFilters() != null && !command.getFilters().isEmpty()) {
        webTarget = webTarget.queryParam("filters", FiltersEncoder.jsonEncode(command.getFilters()));
    }

   if (command.getImageNameFilter() != null) {
        webTarget = webTarget.queryParam("filter", command.getImageNameFilter());
   }

    LOGGER.trace("GET: {}", webTarget);

    List<Image> images = webTarget.request().accept(MediaType.APPLICATION_JSON)
            .get(new TypeReference<List<Image>>() {
            });

    LOGGER.trace("Response: {}", images);

    return images;
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:25,代码来源:ListImagesCmdExec.java


示例14: loadImageFromTar

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@Test
public void loadImageFromTar() throws Exception {
    try (InputStream uploadStream = Files.newInputStream(TestResources.getApiImagesLoadTestTarball())) {
        dockerRule.getClient().loadImageCmd(uploadStream).exec();
    }

    //swarm needs some time to refelct new images
    synchronized (this) {
        wait(5000);
    }

    final Image image = findImageWithId(expectedImageId, dockerRule.getClient().listImagesCmd().exec());

    assertThat("Can't find expected image after loading from a tar archive!", image, notNullValue());
    assertThat("Image after loading from a tar archive has wrong tags!",
            asList(image.getRepoTags()), equalTo(singletonList("docker-java/load:1.0")));
}
 
开发者ID:docker-java,项目名称:docker-java,代码行数:18,代码来源:LoadImageCmdIT.java


示例15: createAndStartContainer

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
private String createAndStartContainer(CreateContainerCmd cmd, PullStrategy pullStrategy, DockerClient client) {
	CompletableFuture<String> respFut = new CompletableFuture<>();
	ListImagesCmd imagesCmd = client.listImagesCmd().withImageNameFilter(cmd.getImage());
	List<Image> imagesList = imagesCmd.exec();
	boolean imageAbsent = imagesList == null || imagesList.size() == 0;
	CompletableFuture<Void> pullFut;
	if(imageAbsent || pullStrategy.equals(PullStrategy.ALWAYS)) {
		pullFut = pullImage(cmd, client);
	} else {
		pullFut = CompletableFuture.completedFuture(null);
	}
	
	pullFut
		.exceptionally(ex -> {
			logger.warning("An error occurred while executing a docker pull operation: " + ex.getMessage());
			return null;
		}).thenRun(() -> {
			String containerId = startContainer(cmd, client);
			respFut.complete(containerId);
		})
		.exceptionally(ex -> {
			respFut.completeExceptionally(ex.getCause());
			return null;
		});
	respFut.exceptionally(ex -> {
		logger.severe("Cannot create container. Reason: " + ex.getMessage());
		return null;
	});
	return respFut.join();
}
 
开发者ID:qzagarese,项目名称:dockerunit,代码行数:31,代码来源:DefaultServiceBuilder.java


示例16: imageListNames

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
private ArrayNode imageListNames () {
	ArrayNode result = jacksonMapper.createArrayNode();
	// list them
	List<Image> images = dockerClient.listImagesCmd().exec();

	StringBuilder builder = new StringBuilder();
	images.forEach( image -> {
		// builder.append( "\n" + Arrays.asList( image.getRepoTags() ) );
		result.add( Arrays.asList( image.getRepoTags() ).toString() );
	} );

	logger.info( "Current Images: {}", result );
	return result;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:15,代码来源:DockerHelper.java


示例17: imageInfo

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@GetMapping ( "/image/info" )
public ObjectNode imageInfo (
								String id,
								String name )
		throws Exception {
	ObjectNode result = jacksonMapper.createObjectNode();
	try {

		Optional<Image> match = dockerHelper.findImageByName( name );

		if ( match.isPresent() ) {

			InspectImageResponse info = dockerClient.inspectImageCmd( match.get().getId() ).exec();
			result = jacksonMapper.convertValue( info, ObjectNode.class );
		} else {

			result.put( DockerJson.error.key, "Failed to locate image with name: " + name );
		}

	} catch (Exception e) {
		String reason = CSAP.getCsapFilteredStackTrace( e );
		logger.warn( "Failed starting {}, {}", name, reason );
		result.put( DockerJson.error.key, "Failed starting: " + name );
		result.put( DockerJson.errorReason.key, reason );
	}

	return result;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:29,代码来源:ExplorerRequests.java


示例18: verify_image_list

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
@Test
public void verify_image_list ()
		throws Exception {

	logger.info( "Listing images." );
	List<Image> images = dockerClient.listImagesCmd().exec();

	images.forEach( image -> {

		logger.info( "container id: {}, \t tags: {} , \t\t {}",
			image.getId(), image.getRepoTags() );
	} );

}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:15,代码来源:Docker_Java.java


示例19: listImages

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
private String listImages () {
	// list them
	List<Image> images = dockerClient.listImagesCmd().exec();

	StringBuilder builder = new StringBuilder();
	images.forEach( image -> {
		builder.append( "\n" + Arrays.asList( image.getRepoTags() ) );
	} );

	logger.info( "Current Images: {}", builder.toString() );

	return builder.toString();
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:14,代码来源:Docker_Java.java


示例20: listAllImages

import com.github.dockerjava.api.model.Image; //导入依赖的package包/类
private List<Image> listAllImages() {
    try {
        return dockerClient.listImagesCmd().withShowAll(true).exec();
    } catch (RuntimeException e) {
        numberOfDockerDaemonFails.add();
        throw new DockerException("Failed to list all images", e);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:9,代码来源:DockerImpl.java



注:本文中的com.github.dockerjava.api.model.Image类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XMLTestCase类代码示例发布时间:2022-05-21
下一篇:
Java Consumer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap