Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es alignment for 4.x #1742

Merged
merged 22 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
492d52f
Test docs for ES alignment
ryanjdew Jan 9, 2019
2b6f897
Move entity management logic from QS to core lib (#1735)
akshaysonvane Jan 10, 2019
e7622e9
Add triggers for entity model TDE generation (#1734)
ryanjdew Jan 10, 2019
d7fa64b
Merge branch 'develop' into es-alignment
aebadirad Jan 10, 2019
e2f2867
Support for ES models in content creation (#1738)
srinathgit Jan 11, 2019
408f963
Incorporate referenced entity model definitions in same definitions (…
ryanjdew Jan 14, 2019
8607c84
Es alignment - Fix failing tests (#1747)
ryanjdew Jan 15, 2019
68dffcb
Adjust TDEs to be more forgiving
ryanjdew Jan 16, 2019
13d70bc
Retain namespaces when creating search options
ryanjdew Jan 16, 2019
6db0083
Clean up entity models after loading them
ryanjdew Jan 16, 2019
cc582d8
Create 'LoadUserArtifactsCommand' for loading entities, mappings (#1755)
srinathgit Jan 18, 2019
0d045b0
fixing #1736 (#1737)
paxtonhare Jan 11, 2019
b8ff158
Updating test for DHFPROD-1581 (#1740)
bsrikan Jan 11, 2019
b86ef9c
Fix for DHFPROD-590 and DHFPROD-1698 (#1741)
srinathgit Jan 11, 2019
43984f7
Setting content db to final db (#1744)
srinathgit Jan 15, 2019
3806a9a
Revert Spring boot version upgrade for QS (#1748)
akshaysonvane Jan 15, 2019
890adc7
2019 copyright update (#1752)
aebadirad Jan 17, 2019
618fcf0
Updating gradle-dhs.properties to run DHF core tests in DHS (#1753)
bsrikan Jan 17, 2019
193be9d
E2e/qs misc test (#1756)
ayuwono Jan 18, 2019
8657eb1
Move entity management logic from QS to core lib (#1735)
akshaysonvane Jan 10, 2019
c48d54c
Create 'LoadUserArtifactsCommand' for loading entities, mappings (#1755)
srinathgit Jan 18, 2019
b8dc641
Merge branch 'develop' into es-alignment
aebadirad Jan 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.marklogic.hub;

import com.marklogic.hub.impl.EntityManagerImpl;
import com.marklogic.hub.entity.HubEntity;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
* Manages existing entities' MarkLogic Server database index settings and query options.
Expand Down Expand Up @@ -57,4 +59,10 @@ public interface EntityManager {
boolean deployFinalQueryOptions();

boolean deployStagingQueryOptions();

List<HubEntity> getEntities();

HubEntity saveEntity(HubEntity entity, Boolean rename) throws IOException;

void deleteEntity(String entity) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public interface HubProject {
*/
Path getHubSecurityDir();

/**
* Gets the path for the hub's triggers directory
*
* @return the path for the hub's triggers directory
*/
Path getHubTriggersDir();

/**
* Gets the path for the user config directory
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2012-2019 MarkLogic Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.marklogic.hub.deploy.commands;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.marklogic.appdeployer.command.AbstractCommand;
import com.marklogic.appdeployer.command.CommandContext;
import com.marklogic.appdeployer.command.SortOrderConstants;
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.datamovement.WriteEvent;
import com.marklogic.client.document.DocumentWriteSet;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.hub.HubConfig;
import com.marklogic.hub.deploy.util.EntityDeploymentUtil;

import java.util.Set;

/*
* Additional command to load entity model JSON that needs to run after the triggers are loaded.
*/
@Component
public class LoadEntityModelsCommand extends AbstractCommand {

@Autowired
private HubConfig hubConfig;

public LoadEntityModelsCommand() {
super();
setExecuteSortOrder(SortOrderConstants.DEPLOY_TRIGGERS + 1);
}

@Override
public void execute(CommandContext context) {
DatabaseClient stagingClient = hubConfig.newStagingClient();
DatabaseClient finalClient = hubConfig.newFinalClient();
JSONDocumentManager finalEntityDocMgr = finalClient.newJSONDocumentManager();
JSONDocumentManager stagingEntityDocMgr = stagingClient.newJSONDocumentManager();

DocumentWriteSet finalWriteSet = finalEntityDocMgr.newWriteSet();
DocumentWriteSet stagingWriteSet = stagingEntityDocMgr.newWriteSet();
EntityDeploymentUtil entityDeployUtil = EntityDeploymentUtil.getInstance();
Set<String> entityURIs = entityDeployUtil.getEntityURIs();
for (String entityURI : entityURIs) {
WriteEvent writeEvent = entityDeployUtil.dequeueEntity(entityURI);
finalWriteSet.add(entityURI, writeEvent.getMetadata(), writeEvent.getContent());
stagingWriteSet.add(entityURI, writeEvent.getMetadata(), writeEvent.getContent());
}
if (finalWriteSet.size() > 0) {
finalEntityDocMgr.write(finalWriteSet);
stagingEntityDocMgr.write(stagingWriteSet);
}
entityDeployUtil.reset();
finalClient.release();
stagingClient.release();
}

public void setHubConfig(HubConfig hubAdminConfig) {
this.hubConfig = hubAdminConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.marklogic.hub.EntityManager;
import com.marklogic.hub.FlowManager;
import com.marklogic.hub.HubConfig;
import com.marklogic.hub.deploy.util.EntityDeploymentUtil;
import com.marklogic.hub.deploy.util.HubFileFilter;
import com.marklogic.hub.error.LegacyFlowsException;
import com.marklogic.hub.flow.Flow;
Expand Down Expand Up @@ -218,8 +219,6 @@ public void execute(CommandContext context) {
}

//for now we'll use two different document managers
JSONDocumentManager finalEntityDocMgr = finalClient.newJSONDocumentManager();
JSONDocumentManager stagingEntityDocMgr = stagingClient.newJSONDocumentManager();
JSONDocumentManager finalMappingDocMgr = finalClient.newJSONDocumentManager();
JSONDocumentManager stagingMappingDocMgr = stagingClient.newJSONDocumentManager();
DocumentWriteSet finalMappingDocumentWriteSet = finalMappingDocMgr.newWriteSet();
Expand Down Expand Up @@ -263,15 +262,13 @@ else if (isEntityDir(dir, startPath.toAbsolutePath())) {
DocumentMetadataHandle meta = new DocumentMetadataHandle();
meta.getCollections().add("http://marklogic.com/entity-services/models");
documentPermissionsParser.parsePermissions(hubConfig.getModulePermissions(), meta.getPermissions());
EntityDeploymentUtil entityDeployUtil = EntityDeploymentUtil.getInstance();
for (Resource r : modules.getAssets()) {
if (forceLoad || modulesManager.hasFileBeenModifiedSinceLastLoaded(r.getFile())) {
InputStream inputStream = r.getInputStream();
StringHandle handle = new StringHandle(IOUtils.toString(inputStream));
inputStream.close();
finalEntityDocMgr.write("/entities/" + r.getFilename(), meta, handle);

// Uncomment to send entity model to staging db as well
stagingEntityDocMgr.write("/entities/" + r.getFilename(), meta, handle);
entityDeployUtil.enqueueEntity("/entities/" + r.getFilename(), meta, handle);
modulesManager.saveLastLoadedTimestamp(r.getFile(), new Date());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2012-2019 MarkLogic Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.marklogic.hub.deploy.util;

import com.marklogic.client.datamovement.WriteEvent;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.marker.AbstractWriteHandle;
import com.marklogic.client.io.marker.DocumentMetadataWriteHandle;
import com.marklogic.client.io.marker.JSONWriteHandle;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/*
* Singleton to aid with Entity deployment. Needed as bridge between walking the entities file structure
* on modules deploy and inserting entity JSON models in the database after triggers are created.
*/
public class EntityDeploymentUtil {
private ConcurrentHashMap<String, DocumentMetadataHandle> metaMap = new ConcurrentHashMap<String, DocumentMetadataHandle>();
private ConcurrentHashMap<String, JSONWriteHandle> contentMap = new ConcurrentHashMap<String, JSONWriteHandle>();

private static EntityDeploymentUtil instance;

public static synchronized EntityDeploymentUtil getInstance() {
if(instance == null){
instance = new EntityDeploymentUtil();
}
return instance;
}

public Set<String> getEntityURIs() {
return contentMap.keySet();
}

public void enqueueEntity(String uri, DocumentMetadataHandle meta, JSONWriteHandle content) {
metaMap.put(uri, meta);
contentMap.put(uri, content);
}

public WriteEvent dequeueEntity(String uri) {
DocumentMetadataHandle meta = metaMap.get(uri);
JSONWriteHandle content = contentMap.get(uri);
return new WriteEventImpl(uri, meta, content);
}

public void reset() {
metaMap.clear();
contentMap.clear();
}

private class WriteEventImpl implements WriteEvent {
private String uri;
private DocumentMetadataHandle meta;
private JSONWriteHandle content;

public WriteEventImpl(String uri, DocumentMetadataHandle meta, JSONWriteHandle content) {
this.uri = uri;
this.meta = meta;
this.content = content;
}

@Override
public String getTargetUri() {
return uri;
}

@Override
public AbstractWriteHandle getContent() {
return content;
}

@Override
public DocumentMetadataWriteHandle getMetadata() {
return meta;
}

@Override
public long getJobRecordNumber() {
return 0;
}

@Override
public long getBatchRecordNumber() {
return 0;
}
}

}

This file was deleted.

Loading