1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | if (checkcache(request, resource.getLastModified())){ // 如果在浏览器缓存中,返回 HTTP status code 304 response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } private boolean checkcache(HttpServletRequest req, long FileModified){ if (isdebug) //开发环境需要重新加载静态资源文件 return false; long ModifiedSince = -1L; try{ ModifiedSince = req.getDateHeader("If-Modified-Since"); } catch (IllegalArgumentException iae){ ModifiedSince = -1L; } long systemTime = System.currentTimeMillis(); if (ModifiedSince != -1L){ if (ModifiedSince / 1000L == FileModified / 1000L){ return true; // 返回304 } if ((systemTime >= ModifiedSince) && (ModifiedSince > FileModified)){ return true; // 返回304 } if (systemTime < ModifiedSince){ LOG.log(Level.FINEST, "The IfModifiedSince date is later than the server's current time so it is invalid, ignore."); } } return false; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | File file = new File(nfsfilepath); if (file.isFile()) { long lastModified = file.lastModified();//获取文件的被修改的时间戳 resource.setLastModified(lastModified); LOG.log(Level.INFO, "The web resource from NFS server is " + nfsfilepath + " and the last modified time is " + lastModified); if (isdebug || !cache.containsKey(resourcePath))//查看缓存信息 { try { byte[] bytes = NFSFileUtil.nfs_getFileBytes(file, NFSFileUtil.NFS_RETRY_SECONDS); resource.setData(bytes);//从NFS 服务器上读取到资源文件 LOG.log(Level.INFO, "Obtained web resource from NFS server for - " + nfsfilepath); } catch (IOException e) { LOG.log(Level.SEVERE, "Failed to obtain web resource from NFS server for - " + nfsfilepath, e); return null; } } } else { LOG.log(Level.SEVERE, "Failed to obtain web resource's lastModified and data from NFS server for - " + nfsfilepath); return null; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | def updateZookeeperNode(): print "The online version is %s" % ONLINE_VERSION #打印当前准备上线的版本号 if (ONLINE_VERSION in [None,'']): logging.error("Severe error - the version to be onlined is empty.") return offline = None try: baseTN = registryParser.getBaseTopologyName() #获取云平台的名称 side = registryParser.getTopologyName() #获取云平台环境即将上线的面,值是A 或 B versionPath = '/%s/data/SampleApp/version/%s' %(baseTN, side) #版本路径信息 sideValue = zooKeeperClient.getData(versionPath)#获得该环境上已经上线的版本号 if (sideValue == "null" or sideValue in [None,'']): #节点上还没有上线的版本号,第一次上线 print "Create node %s on zookeeper and its value is %s" % (versionPath, ONLINE_VERSION) logging.info("Create node %s on zookeeper and its value is %s" % (versionPath, ONLINE_VERSION)) zooKeeperClient.createNode(versionPath, ONLINE_VERSION) #节点上存储上线的版本号 return else: logging.info("Old %s SampleApp version is %s" % (side, sideValue))#输出旧的版本号 if(sideValue != ONLINE_VERSION): zooKeeperClient.setData(versionPath, ONLINE_VERSION) #新版本上线 logging.info("New %s SampleApp version is %s" % (side, ONLINE_VERSION)) children = zooKeeperClient.getChildNodes('/%s/data/SampleApp/version' %(baseTN)) offlineFlag = True for node in children: # 循环查看即将下线的版本在其他云平台环境中有没有被用到 #Filter itself and empty side name if(node == side or node == ''): continue else: data = zooKeeperClient.getData('/%s/data/SampleApp/version/%s' %(baseTN, node)) if(data == sideValue): offlineFlag = False #其他环境正在使用该版本号,不删除其在NFS上的资源文件 break if(offlineFlag): offline = sideValue # 没有其他环境用到,旧版本准备下线 else: logging.info("The obsolete version %s is still using by anther side." % sideValue) else: print "Flip failover case - no new version is online." logging.info("Flip failover case - no new version is online.") if (offline is not None): logging.info("The offline version is %s" % offline) global OFFILE_VERSION OFFILE_VERSION = offline except Exception,e: logging.error(e) raise |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |