往 ABAP gateway system 上和 CloudFoundry 部署 HTML5 应用

ABAP Gateway system
在我的公众号文章里有详细介绍:SAP Fiori应用的三种部署方式
用 WebIDE 部署
用 Eclipse Team provider 部署
执行 report /UI5/UI5_UPLOAD_INTO_MIME
Cloud Foundry
在 manifest.yml 文件里指定 buildpack,

然后到 manifest.yml 文件所在的根目录下,执行命令行:
cf push -f ./approuter-manifest.ymlcf push 首先会将整个应用的文件上传到 Cloud Foundry 上:
![]()
因为我的 manifest.yml 里未指定 Nodejs buildpack 的版本号,因此使用服务器上默认版本 1.6.21:

下载 nodejs buildpack 后进行 build:

build 成功:

在 build 日志能能看到详细步骤。

部署应用的详细过程在CloudFoundry官网上有介绍
使用 SAP 云平台的 CloudFoundry 部署应用:

在 cockpit 遇到错误信息:instance: a0abe2b5-7623-4cf1-4c65-0c79, index: 0, exit_description: APP/PROC/WEB: Exited with status 254, reason: CRASHED


使用命令查看部署日志:cf logs connectvity-demo-approuter --recent
2018-05-30T11:33:30.95+0800 [CELL/0] OUT Starting health monitoring of container2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! Linux 4.4.0-119-generic2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! argv "/home/vcap/deps/0/node/bin/node" "/home/vcap/deps/0/bin/npm" "start"2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! node v6.13.12018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! npm v3.10.102018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! path /home/vcap/app/package.json2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! code ENOENT2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! errno -22018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! syscall open2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! enoent ENOENT: no such file or directory, open '/home/vcap/app/package.json'2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! enoent ENOENT: no such file or directory, open '/home/vcap/app/package.json'2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! enoent This is most likely not a problem with npm itself2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! enoent and is related to npm not being able to find a file.2018-05-30T11:33:31.68+0800 [APP/PROC/WEB/0] ERR npm ERR! enoent2018-05-30T11:33:31.69+0800 [APP/PROC/WEB/0] ERR npm ERR! Please include the following file with any support request:发现原因是 build 时找不到 package.json. 但我确认我部署的 zip 文件里存在 package.json
解决方案
使用 CLI 进行部署:
cf push -f ./approuter-manifest.yml 问题解决:


Netweaver
要记录日志需要有一个 checkpoint group,可以自行创建也可以使用标准的。这里我重用标准的 group:DEMO_CHECKPOINT_GROUP。
tcode SAAB,点 Display <->Activate 进入编辑模式,将 Logpoints 设置为"Log",日期设为 Today,意为当天生效。

Netweaver 的日志记录大多是基于用户级别的,这一点比较方便。给想打开日志记录的用户创建一个打开日志开关的配置:

新建一个 report 名称为 ZCONTEXT, 下面代码的含义是把当前 report 名称(包含在环境变量 sy-cprog)和当前 report 的运行环境(online 运行还是 offline 运行)写入该 checkpoint group。因为可能有其他人也会使用该 group,所以用 SUBKEY 区分不同的用户。

执行完 report 后返回 SAAB 即可查看到记录的日志。

双击能看到记录的明细。

CloudFoundry
总的 guideline 在SAP官方Github上有。
这里简述要点。
SAP 云平台的 CloudFoundry 环境里的日志记录推荐使用 slf4j(Simple Log Facade for Java)。即 Java 代码里使用 slf4j 提供的接口进行日志记录,而具体的日志记录实现可以通过配置文件来指定。
我做了一个例子,全部源代码在我的github上。我的例子使用 log4j2 作为日志记录的实现。
(1) 在 Java 项目的 pom.xml 里定义 slf4j 和 log4j2 的版本号。
在 pom.xml 文件的 dependency 区域维护相关的 dependency:
(2) 在 CLASSPATH 下新建 log4j2.xml, 使用如下源代码:
(3) 在 SAP 云平台 Cockpit 里创建一个新的 log instance:

取名为 jerry-log:

(4) 代码里的使用:
然后使用 LOGGER.info 记录日志。

(5) 如何查询记录的日志:点击 Logs 标签页->Open Kibanna Dashboard, 能看到上图"Diablo Connecting to backend system"对应的日志:

在 log 明细里能看到之前在 SAP 云平台 Cockpit 里创建的 Log service 实例。

版权声明: 本文为 InfoQ 作者【Jerry Wang】的原创文章。
原文链接:【http://xie.infoq.cn/article/9a0673aa881e19e86302f5a66】。文章转载请联系作者。
评论