【发布时间】:2018-09-23 22:16:57
【问题描述】:
我的目标(背景信息)
我想在 cumulocity 上开发一个 java 微服务。它应该能够执行以下操作:
我会向微服务发送“112233”,如下所示:
https://myTenant.cumulocity.com/service/my-application-name/decode?data=112233
然后,微服务应将数据拆分为“11”用于第一次测量,“22”用于第二次测量等。这些测量将被 POST 到 cumulocity。
我的问题
我现在坚持让Hello, microservice tutorial 工作。我无法将微服务(zip 文件)部署到 cumulocity。
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}(我是管理员用户)
我还尝试通过网站上传 zip 文件,这创建了一个 HOSTED 应用程序而不是 MICROSERVICE。通过 POST 请求将我的 zip 上传到 HOSTED 应用程序实际上可以工作(我显然不需要)。
我怀疑我收到“拒绝访问”错误,因为 cumulocity 认为我将 HOSTED 应用程序上传到 MICROSERVICE。
到目前为止我做了什么
代码端
我从 cumulocity bitbucket 开发分支下载了hello-world-microservice example。 (此代码在默认分支上不可用)。
我将cumulocity版本更改为9.3.0,似乎只有这个版本存在。
HelloWorldMain.java 未经编辑
这是我的 cumulocity.json 清单文件:(角色没有区别)
{
"apiVersion":"1",
"type":"MICROSERVICE",
"version":"@project.version@",
"availability":"PRIVATE",
"provider":{
"name":"Cumulocity GmbH"
},
"isolation":"MULTI_TENANT",
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"livenessProbe":{
"httpGet":{
"path":"/health",
"port":80
},
"initialDelaySeconds":15,
"periodSeconds":10
},
"readinessProbe":{
"httpGet":{
"path":"/health",
"port":80
}
}
}
这是我的 application.properties 文件
application.name=my-application-name
server.port=80
C8Y.baseURL=https://myTenant.cumulocity.com
C8Y.bootstrap.tenant=myTenant
C8Y.bootstrap.user=servicebootstrap_my-application-name
C8Y.bootstrap.password={SECRET_BOOTSTRAP_PASSW}
C8Y.user={MY_USERNAME}
C8Y.password={SECRET_PASSW}
C8Y.bootstrap.register=true
C8Y.microservice.isolation=MULTI_TENANT
C8Y.bootstrap.initialDelay=10000
积水面
我成功创建了一个微服务应用程序,
GET https://myTenant.cumulocity.com/application/applications/5886 返回:
{
"availability":"PRIVATE",
"id":"5886",
"key":"my-application-key",
"manifest":{
"imports":[
],
"noAppSwitcher":true
},
"name":"my-application-name",
"owner":{
"self":"https://myTenant.cumulocity.com/tenant/tenants/myTenant",
"tenant":{
"id":"myTenant"
}
},
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"self":"https://myTenant.cumulocity.com/application/applications/5886",
"type":"MICROSERVICE"
}
我也成功地订阅了这个应用程序。
当我尝试将 zip 文件上传到 cumulocity 时,我收到以下错误:
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(上传到HOSTED 类型的应用程序可以正常工作,但我不希望这样。)
注意:我也尝试使用microservice deploy script,这与手动执行所有操作的结果相同。
尝试在本地运行
由于我无法让它在 cumulocity 平台上运行,我尝试通过 docker 在本地运行它。我用这个命令运行它:docker run -e "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" 10aa0b73ddb3
注意:我必须添加“C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT”environment variable。如果我不添加这个,我会遇到凭据/权限问题。这对我来说似乎很奇怪,因为除了这个之外,所有其他信息都是从 application.properties 文件中读取的。
在本地 docker 上运行此映像时没有错误。
根据Hello, microservice tutorial,我应该可以请求curl -H "Authorization: {AUTHORIZATION}" https://myTenant.cumulocity.com/service/my-application-name/hello?who=me
这将返回:{"error":"microservice/Not Found","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Microservice my-application-name not found."}
回到问题
有没有其他人在 cumulocity 上设置微服务时遇到困难?
有什么我要完全监督的吗?
【问题讨论】:
标签: java microservices cumulocity