当前位置: 首页 > news >正文

一次性医用口罩价格网站建设推广优化

一次性医用口罩价格,网站建设推广优化,哈尔滨最新通知今天,重庆网站优化网络服务Java model 准备 首先使用 crd.yml 和 kubernetes CRD 自动生成 Java model 类,这是一切的前提,之前在这个地方也卡了很久。如何生成在另外一个文章中已经有所记录。 使用 crd.yml 和 kubernetes CRD 自动生成 Java model 类 CustomObjectsApi 文档学习…

Java model 准备

首先使用 crd.yml 和 kubernetes CRD 自动生成 Java model 类,这是一切的前提,之前在这个地方也卡了很久。如何生成在另外一个文章中已经有所记录。
使用 crd.yml 和 kubernetes CRD 自动生成 Java model 类

CustomObjectsApi 文档学习

官网 kubernetes-client/java 的 CustomObjectsApi 介绍使用
在这个里面我们能找到所有关于自定义资源的增删改查的 api 的操作,还有示范的例子,可以根据自己的需求进行相关的改造使用。

示例

1、查看所有的自定义资源列表

public List<V1alpha1xxxx> getxxxList() {log.info("getxxxxList start to work");CustomObjectsApi apiInstance = kubernetesService.getCustomObjectsApi();Object result = null;try {result =apiInstance.listNamespacedCustomObject(group, version, namespace, plural, null, null, null, null, null, null, null, null,null, null);} catch (ApiException e) {log.info("listNamespacedCustomObject api call failed with status code "+ e.getCode()+ ": "+ e.getResponseBody());e.printStackTrace();}ObjectMapper objectMapper = kubernetesApplicationService.getObjectMapper();V1alpha1xxxList v1alpha1xxxList =objectMapper.convertValue(result, V1alpha1xxxList.class);return v1alpha1xxxList.getItems();}

2、得到指定的某一个自定义资源

public V1alpha1xxx getxxx(String name) {log.info("getxxx start to work");//        "name": "admin-1akyr08e9wwt"Object result =kubernetesApplicationService.getCustomObjectsApi(group, version, namespace, plural, name);ObjectMapper objectMapper = kubernetesApplicationService.getObjectMapper();V1alpha1xxx v1alpha1xxx = objectMapper.convertValue(result, V1alpha1xxx.class);return v1alpha1xxx;
}

CustomObjectsApi 去获得指定的某一个自定义资源

public Object getCustomObjectsApi(String group, String version, String namespace, String plural, String name) {CustomObjectsApi apiInstance = kubernetesService.getCustomObjectsApi();Object result = null;try {result = apiInstance.getNamespacedCustomObject(group, version, namespace, plural, name);} catch (ApiException e) {if (e.getCode() == 404) {log.info("custom object {} does not exist", name);} else {log.info("getNamespacedCustomObject api call failed with status code "+ e.getCode()+ ": "+ e.getResponseBody());e.printStackTrace();}}return result;}

3、创建一个自定义资源

public V1alpha1xxx createxxx(V1alpha1xxx v1alpha1xxxb) {log.info("createxxx start to work");Object customObject =kubernetesApplicationService.createNamespacedCustomObject(group,version,namespace,plural,v1alpha1xxx.getMetadata().getName(),v1alpha1xxx);return v1alpha1xxx;

CustomObjectsApi去创建一个自定义的资源

public Object createNamespacedCustomObject(String group,String version,String namespace,String plural,String name,KubernetesObject kubernetesObject) {CustomObjectsApi apiInstance = kubernetesService.getCustomObjectsApi();Object customObject = null;try {customObject =apiInstance.createNamespacedCustomObject(group, version, namespace, plural, kubernetesObject, null, null, null);log.info("createNamespacedCustomObject {}", name);} catch (ApiException e) {log.info("createNamespacedCustomObject api call failed with status code "+ e.getCode()+ ": "+ e.getResponseBody());e.printStackTrace();}return customObject;}

4、删除自定义资源

 public void deleteBayesJob(String name) {log.info("deletexxx {} start to work", name);V1alpha1xxx xxx = getxxx(name);if (xxx == null) {log.error("can not get xxx {}", name);return;}kubernetesApplicationService.deleteNamespacedCustomObject(group, version, namespace, plural, name);}

CustomObjectsApi删除指定的自定义资源

public void deleteNamespacedCustomObject(String group, String version, String namespace, String plural, String name) {V1DeleteOptions body = new V1DeleteOptions();CustomObjectsApi apiInstance = kubernetesService.getCustomObjectsApi();try {Object result =apiInstance.deleteNamespacedCustomObject(group, version, namespace, plural, name, null, null, null, null, body);log.info("delete namespaced customObject {}", name);} catch (ApiException e) {log.info("deleteNamespacedCustomObject api call failed with status code "+ e.getCode()+ ": "+ e.getResponseBody());e.printStackTrace();}}

5、修改自定义资源

public void killxxx(String name) {log.info("killxxx start to work");CustomObjectsApi apiInstance = kubernetesService.getCustomObjectsApi();V1alpha1xxx bxxx = getBaxxx(name);if (bxxx== null) {log.error("can not get bxxx {}", name);throw new InvalidRequestException("invalid name " + name);}Map<String, String> annotations = bxxx.getMetadata().getAnnotations();if (annotations == null) {bxxx.getMetadata().setAnnotations(new HashMap<>() {{put("xxxxx/terminate", "true");}});} else {bxxx.getMetadata().getAnnotations().put("xxxx/terminate", "true");}ObjectMapper objectMapper = kubernetesApplicationService.getObjectMapper();String bxxxAsString = null;try {bxxxAsString = objectMapper.writeValueAsString(bxxx);} catch (JsonProcessingException e) {log.error("killxxx writeValueAsString error {}", e.getMessage());e.printStackTrace();throw new RuntimeException(e);}Gson gson = new Gson();JsonObject jsonObject = gson.fromJson(bayesJobAsString, JsonObject.class);kubernetesApplicationService.replaceNamespacedCustomObject(group, version, namespace, plural, jsonObject, name);
}

CustomObjectsApi replace某一个自定义资源

public void replaceNamespacedCustomObject(String group,String version,String namespace,String plural,JsonObject jsonObject,String name) {log.info("replaceNamespacedCustomObject name {} ,jsonObject {}", name, jsonObject);CustomObjectsApi apiInstance = kubernetesService.getCustomObjectsApi();try {Object result =apiInstance.replaceNamespacedCustomObject(group, version, namespace, plural, name, jsonObject, null, null);log.info("replaceNamespacedCustomObject name {} result {}", name, result);} catch (ApiException e) {log.error("Exception when calling CustomObjectsApi#replaceNamespacedCustomObject");log.error("Status code: {} , Reason: {}", e.getCode(), e.getResponseBody());e.printStackTrace();}}

这个是先查找自定义资源A是否存在,如果存在的话,修改自定义资源A的某些属性,然后将其A进行序列化。之后 gson.fromJson 然后再进行自定义资源A的replace

http://www.mmbaike.com/news/76020.html

相关文章:

  • 网站搭建南京广州营销型网站
  • 动态网站的格式semen
  • tomcat做网站app拉新推广赚佣金
  • 香港政府网站建设经验广西seo经理
  • 做海报创客贴同类网站平台推广是什么
  • 投稿网站源码深圳全网营销型网站
  • 嘉定专业网站制作公司富阳seo关键词优化
  • 湛江购房网官方网站网站优化外包公司
  • 做网站宽度和长度布局竞价服务托管公司
  • 深圳网站搜索引擎优化网络营销计划的七个步骤
  • 企信查官网网络seo首页
  • 网站keyword如何排序百度浏览器网址是多少
  • 做美女图片网站需要备案吗福州seo排名优化
  • 哪家公司网站建设好点广东网络推广运营
  • 做诱惑类cpa网站经验网站推广哪个好
  • 云南文山地图网站优化技巧
  • php网站数据迁移seo搜索优化推广
  • 不属于企业网站建设基本标准是站长是什么级别
  • wordpress本地环境链接404上海优化价格
  • 专业营销网站带客成都网站优化及推广
  • 做化妆品的网站有哪些百度官方电话
  • 建设推广营销型网站应该注意什么千锋教育官网
  • 旅游网站建设方案书范文百度com打开
  • 小白自己做网站seo怎样才能优化网站
  • wordpress添加内容在头部杭州网站建设 seo
  • 中山网站建设gdyouzi互联网推广销售
  • 有了源码怎么做网站徐州seo外包
  • 怎么做网站主导航南京seo网络推广
  • 美的网站建设天天seo百度点击器
  • 网站备案服务内容郑州seo技术顾问