Search in sources :

Example 1 with ISchemaPluginContext

use of com.qlangtech.tis.solrdao.ISchemaPluginContext in project tis by qlangtech.

the class UploadJarAction method parseSnapshot.

/**
 * 创建snapshot
 *
 * @param context
 * @param formm
 * @return
 * @throws IOException
 */
protected Snapshot parseSnapshot(Context context, UploadJarForm formm, SnapshotCreater snapshotCreater) throws IOException {
    ConfigContentGetter[] getter = getContentGetter(formm);
    ConfigFileValidateResult validateValidateResult = null;
    boolean fileValid = true;
    // 校验文件格式是否正确
    ISchemaPluginContext schemaPlugin = SchemaAction.createSchemaPlugin(this.getCollectionName());
    for (ConfigContentGetter get : getter) {
        validateValidateResult = get.getterStrategy.validate(schemaPlugin, get.content);
        if (!validateValidateResult.isValid()) {
            this.addErrorMessage(context, validateValidateResult.getValidateResult());
            fileValid = false;
        }
    }
    if (!fileValid) {
        return null;
    }
    // createSnapshot(getter);
    Snapshot snapshot = snapshotCreater.create(getter);
    snapshot.setPreSnId(-1);
    return snapshot;
}
Also used : Snapshot(com.qlangtech.tis.manage.biz.dal.pojo.Snapshot) ISchemaPluginContext(com.qlangtech.tis.solrdao.ISchemaPluginContext) ConfigFileValidateResult(com.qlangtech.tis.manage.common.ConfigFileValidateResult)

Example 2 with ISchemaPluginContext

use of com.qlangtech.tis.solrdao.ISchemaPluginContext in project tis by qlangtech.

the class AppSynAction method doInitAppFromDaily.

// private ITerminatorTriggerBizDalDAOFacade triggerContext;
/**
 * 接收从日常环境中推送上来的配置文件,<br>
 * 当第一次推送的时候线上还不存在索引实例的时候,会自动创建索引实例
 *
 * @param context
 * @throws Exception
 */
@Func(PermissionConstant.APP_ADD)
public void doInitAppFromDaily(Context context) throws Exception {
    String content = null;
    try (InputStream reader = this.getRequest().getInputStream()) {
        content = IOUtils.toString(reader, getEncode());
        if (StringUtils.isEmpty(content)) {
            throw new IllegalArgumentException("upload content can not be null");
        }
    }
    final ConfigPush configPush = (ConfigPush) HttpConfigFileReader.xstream.fromXML(content);
    final String collection = configPush.getCollection();
    ISchemaPluginContext schemaPlugin = SchemaAction.createSchemaPlugin(collection);
    // 校验当前的snapshot 版本是否就是传输上来的snapshot版本
    ServerGroup serverGroup = null;
    if (configPush.getRemoteSnapshotId() != null) {
        serverGroup = this.getServerGroupDAO().load(collection, (short) 0, /* groupIndex */
        RunEnvironment.ONLINE.getId());
        if (serverGroup.getPublishSnapshotId() != (configPush.getRemoteSnapshotId() + 0)) {
            this.addErrorMessage(context, "exist snapshotid:" + serverGroup.getPublishSnapshotId() + " is not equal push snapshotid:" + configPush.getRemoteSnapshotId());
            return;
        }
    }
    // List<UploadResource> resources = configPush.getUploadResources();
    Snapshot snapshot = null;
    SnapshotDomain snapshotDomain = null;
    Application app = null;
    ApplicationCriteria criteria = new ApplicationCriteria();
    criteria.createCriteria().andProjectNameEqualTo(collection);
    List<Application> apps = this.getApplicationDAO().selectByExample(criteria);
    for (Application p : apps) {
        app = p;
        break;
    }
    if (app == null) {
        // 在服务端创建新应用
        app = new Application();
    // Integer newAppid = this.createNewApp(context, configPush);
    // app.setAppId(newAppid);
    }
    String snycDesc = "NEW CREATE";
    serverGroup = this.getServerGroupDAO().load(collection, (short) 0, /* groupIndex */
    RunEnvironment.ONLINE.getId());
    boolean newSnapshot = false;
    if (serverGroup == null || serverGroup.getPublishSnapshotId() == null) {
        snapshot = new Snapshot();
        snapshot.setSnId(-1);
        snapshot.setPreSnId(-1);
        snapshot.setAppId(app.getAppId());
        newSnapshot = true;
    } else {
        snycDesc = "PUSH FROM DAILY";
        snapshotDomain = this.getSnapshotViewDAO().getView(configPush.getRemoteSnapshotId());
        snapshot = snapshotDomain.getSnapshot();
    }
    if (snapshot == null) {
        throw new IllegalStateException("snapshot can not be null,collection:" + collection);
    }
    snapshot.setCreateUserId(0l);
    snapshot.setCreateUserName(configPush.getReception());
    // ///////////////////////////////////
    // 组装新的snapshot
    PropteryGetter pGetter = null;
    for (UploadResource res : configPush.getUploadResources()) {
        pGetter = ConfigFileReader.createPropertyGetter(res.getResourceType());
        // 校验配置是否相等
        if (!newSnapshot) {
            final String md5 = ConfigFileReader.md5file(res.getContent());
            if (StringUtils.equals(md5, pGetter.getMd5CodeValue(snapshotDomain))) {
                this.addErrorMessage(context, "resource " + pGetter.getFileName() + " is newest,shall not be updated");
                return;
            }
        }
        Integer newResId = ResSynManager.createNewResource(context, schemaPlugin, res.getContent(), ConfigFileReader.md5file(res.getContent()), pGetter, this, this);
        snapshot = pGetter.createNewSnapshot(newResId, snapshot);
    }
    serverGroup = new ServerGroup();
    serverGroup.setPublishSnapshotId(SaveFileContentAction.createNewSnapshot(snapshot, snycDesc, this, 0l, configPush.getReception()));
    serverGroup.setUpdateTime(new Date());
    ServerGroupCriteria serverGroupCriteria = new ServerGroupCriteria();
    serverGroupCriteria.createCriteria().andAppIdEqualTo(app.getAppId()).andRuntEnvironmentEqualTo(RunEnvironment.ONLINE.getId()).andGroupIndexEqualTo((short) 0);
    this.getServerGroupDAO().updateByExampleSelective(serverGroup, serverGroupCriteria);
    // /////////////////////////////////////
    this.addActionMessage(context, "synsuccess");
}
Also used : SnapshotDomain(com.qlangtech.tis.manage.common.SnapshotDomain) InputStream(java.io.InputStream) Date(java.util.Date) PropteryGetter(com.qlangtech.tis.manage.common.PropteryGetter) ISchemaPluginContext(com.qlangtech.tis.solrdao.ISchemaPluginContext) ConfigPush(com.qlangtech.tis.runtime.pojo.ConfigPush) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 3 with ISchemaPluginContext

use of com.qlangtech.tis.solrdao.ISchemaPluginContext in project tis by qlangtech.

the class SaveFileContentAction method doSaveContent.

/**
 * 保存文本内容
 */
@Func(PermissionConstant.CONFIG_EDIT)
public void doSaveContent(Context context) throws Exception {
    if (!RunEnvironment.isDevelopMode()) {
        this.addErrorMessage(context, "请先更新日常环境中的配置文件,然后同步到线上环境!");
        return;
    }
    Savefilecontent xmlContent = this.parseJsonPost(Savefilecontent.class);
    Integer snapshotid = xmlContent.getSnapshotid();
    String fileName = xmlContent.getFilename();
    // if (isEditSchemaApply(context, fileName)) return;
    PropteryGetter propertyGetter = createConfigFileGetter(fileName);
    Long userid = 999l;
    try {
        userid = new Long(this.getUserId());
    } catch (Throwable e) {
    }
    ISchemaPluginContext schemaPlugin = SchemaAction.createSchemaPlugin(this.getCollectionName());
    CreateSnapshotResult createResult = createNewSnapshot(context, this.getSnapshotViewDAO().getView(snapshotid, false), propertyGetter, schemaPlugin, xmlContent.getContentBytes(), this, this, xmlContent.getMemo(), userid, this.getLoginUserName());
    if (!createResult.isSuccess()) {
        // forward("edit_" + BasicContentScreen.getResourceName(propertyGetter));
        return;
    }
    this.setBizResult(context, createResult);
    this.addActionMessage(context, "保存文件成功,最新snapshot:" + createResult.getNewId());
}
Also used : Savefilecontent(com.qlangtech.tis.manage.Savefilecontent) ISchemaPluginContext(com.qlangtech.tis.solrdao.ISchemaPluginContext) Func(com.qlangtech.tis.manage.spring.aop.Func)

Aggregations

ISchemaPluginContext (com.qlangtech.tis.solrdao.ISchemaPluginContext)3 Func (com.qlangtech.tis.manage.spring.aop.Func)2 Savefilecontent (com.qlangtech.tis.manage.Savefilecontent)1 Snapshot (com.qlangtech.tis.manage.biz.dal.pojo.Snapshot)1 ConfigFileValidateResult (com.qlangtech.tis.manage.common.ConfigFileValidateResult)1 PropteryGetter (com.qlangtech.tis.manage.common.PropteryGetter)1 SnapshotDomain (com.qlangtech.tis.manage.common.SnapshotDomain)1 ConfigPush (com.qlangtech.tis.runtime.pojo.ConfigPush)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1