Example #1
0
std::string wordcountreduce(std::string inputFile, std::string inputFile2)
{
  std::ifstream inFile,inFile2;
  inFile.open(inputFile.c_str(), std::fstream::in);
  inFile2.open(inputFile2.c_str(), std::fstream::in);
  
  uint64_t i,count;
  std::string str;

  inFile>> str>> i;
  count =i;
  inFile2>>str >>i;
  count = count +i;
  std::stringstream ss;

  ss.clear();
  ss<<PATH<<getpid()<<"reduce"<<fileAppend();
  std::string pidstr(ss.str());

  std::ofstream outFile;
  outFile.open(pidstr.c_str(), std::fstream::out);
  outFile<<"count "<<count<<std::endl;
  outFile.close();
  return ss.str();

}
Example #2
0
std::string wordcountmap(std::string inputFile, int64_t startOffset, int64_t endOffset)
{
  std::ifstream inFile;
  inFile.open(inputFile.c_str(), std::fstream::in);
  inFile.seekg (startOffset, inFile.beg); //read all till < endOffset
  std::string token;
  std::stringstream ss;
  uint64_t count =0;
 
  while(inFile.tellg() < endOffset){
    getNextWord(inFile,token," ",endOffset); //tokenizer

    if(token.size() == 0) continue;

    count++;
  }

  inFile.close();

  ss.clear();
  ss<<PATH<<getpid()<<fileAppend();
  std::string pidstr(ss.str());

  std::ofstream outFile;
  outFile.open(pidstr.c_str(), std::fstream::out);
  outFile<<"count "<<count<<std::endl;
  outFile.close();
  return ss.str();

}
Example #3
0
void CBlackBox::Boot (const CString &sPath)

//	Boot
//
//	Prepare the log file

	{
	ASSERT(!m_File.IsOpen());

	//	Generate a filename using the current date and time

	CDateTime Now(CDateTime::Now);
	CString sFilename = strPattern("BlackBox_%04d%02d%02d_%02d%02d%02d.log",
			Now.Year(),
			Now.Month(),
			Now.Day(),
			Now.Hour(),
			Now.Minute(),
			Now.Second());

	//	Create the file

	CString sError;
	if (!m_File.Create(fileAppend(sPath, sFilename), CFile::FLAG_CREATE_ALWAYS, &sError))
		//	LATER: Handle error somehow.
		NULL;
	}
Example #4
0
bool CAeonEngine::OpenTableDefinitions (void)

//	OpenTableDefinitions
//
//	Opens and reads all tables in all volumes. Note that we have no idea what
//	could have happened since our last boot--someone could have copied files
//	all over the place. We make almost no assumptions.

	{
	CSmartLock Lock(m_cs);

	int i, j;
	CString sError;

	//	Loop over all volumes and end up with a list of tables and volumes

	TSortMap<CString, TArray<CString>> Tables;
	for (i = 0; i < m_LocalVolumes.GetCount(); i++)
		{
		CString sVolume = m_LocalVolumes.GetVolume(i);

		TArray<CString> Dirs;
		fileGetFileList(fileAppend(m_LocalVolumes.GetPath(i), FILESPEC_TABLE_DIR_FILTER), FFL_FLAG_DIRECTORIES_ONLY | FFL_FLAG_RELATIVE_FILESPEC, &Dirs);

		for (j = 0; j < Dirs.GetCount(); j++)
			{
			TArray<CString> *pList = Tables.SetAt(Dirs[j]);
			pList->Insert(sVolume);
			}
		}

	//	Open all tables

	for (i = 0; i < Tables.GetCount(); i++)
		{
		CString sName = Tables.GetKey(i);

		CAeonTable *pTable = new CAeonTable;
		if (!pTable->Open(GetProcessCtx(), &m_LocalVolumes, sName, Tables[i], &sError))
			{
			Log(MSG_LOG_ERROR, strPattern("Unable to load %s: %s", sName, sError));
			delete pTable;
			continue;
			}

		m_Tables.Insert(sName, pTable);
		}

	//	Done

	return true;
	}
Example #5
0
std::string wordcountMapreduce(std::string inputFile, std::string inputFile2)
{
  std::ifstream inFile,inFile2;
  inFile.open(inputFile.c_str(), std::fstream::in);
  inFile2.open(inputFile2.c_str(), std::fstream::in);
  
  uint64_t i;
  std::string str;
  std::map<std::string, int> wcMap;
 

  while(inFile>> str>> i){
      wcMap[str] = i; 
  }

  while(inFile2>> str>> i){
   if(wcMap.count(str)){
      wcMap[str] = wcMap[str] + i;  
   }else{
      wcMap[str] = i;  
   }
  }

  std::stringstream ss;

  ss.clear();
  ss<<PATH<<getpid()<<"reduce"<<fileAppend();
  std::string pidstr(ss.str());

  std::ofstream outFile;
  outFile.open(pidstr.c_str(), std::fstream::out);

  std::map<std::string, int>::iterator it;
  for(it = wcMap.begin();it!= wcMap.end(); it++){
  outFile<<it->first<<"  "<<it->second<<std::endl;
  }

  outFile.close();
  return ss.str();

}
Example #6
0
std::string wordcountMapmap(std::string inputFile, int64_t startOffset, int64_t endOffset)
{
  std::ifstream inFile;
  inFile.open(inputFile.c_str(), std::fstream::in);
  inFile.seekg (startOffset, inFile.beg); //read all till < endOffset
  std::string token;
  std::stringstream ss;
  std::map<std::string, int> wcMap;
 
  while(inFile.tellg() < endOffset){
    getNextWord(inFile,token," ",endOffset); //tokenizer

    if(!token.compare(" ")) continue;
    if(token.size()==0) continue;
    
    if(wcMap.count(token)){
      wcMap[token]++;
    }else{
      wcMap[token]=1;
    }
  }

  inFile.close();

  ss.clear();
  ss<<PATH<<getpid()<<fileAppend();
  std::string pidstr(ss.str());

  std::ofstream outFile;
  outFile.open(pidstr.c_str(), std::fstream::out);

  std::map<std::string, int>::iterator it;
  for(it = wcMap.begin();it!= wcMap.end(); it++){
  outFile<<it->first<<"  "<<it->second<<std::endl;
  }
  outFile.close();
  return ss.str();

}
Example #7
0
CString ExecuteUploadPackage (CSocket &theSocket, const CString &sCmd)
	{
	int i;
	char *pPos = sCmd.GetParsePointer() + STR_UPLOAD_PACKAGE_PREFIX.GetLength();
	
	//	Get the package name

	if (*pPos == '\"')
		pPos++;

	char *pStart = pPos;
	while (*pPos != ' ' && *pPos != '\"' && *pPos != '\0')
		pPos++;

	CString sPackageName(pStart, pPos - pStart);
	if (*pPos != '\0')
		pPos++;

	if (*pPos == '\"')
		pPos++;

	//	Skip whitespace

	while (*pPos == ' ')
		pPos++;
	
	//	Get the filespec

	pStart = pPos;
	while (*pPos != '\0')
		pPos++;

	CString sFilespec(pStart, pPos - pStart);

	//	Get the directory

	CString sPackageFolder = fileGetPath(sFilespec);
	CString sPackageDescFilespec = fileGetFilename(sFilespec);

	//	Upload the package descriptor

	CString sPackageDesc = strPattern("/Arc.services/%s.ars", sPackageName);
	printf("Uploading %s to /Arc.services/%s.ars...", (LPSTR)sFilespec, (LPSTR)sPackageName);
	CString sResult = UploadFile(theSocket, CMD_UPLOAD, sPackageDesc, sFilespec);
	printf("%s\n", (LPSTR)sResult);

	//	Now loop over all files in the directory

	TArray<CString> Files;
	if (!fileGetFileList(fileAppend(sPackageFolder, CString("*.*")), 
			FFL_FLAG_RELATIVE_FILESPEC | FFL_FLAG_RECURSIVE,
			&Files))
		{
		printf("ERROR: Unable to list directory: %s\\*.*\n", (LPSTR)sPackageFolder);
		return NULL_STR;
		}

	for (i = 0; i < Files.GetCount(); i++)
		{
		if (!strEquals(Files[i], sPackageDescFilespec))
			{
			CString sFilePath = strPattern("/Arc.services/%s/%s", sPackageName, CAeonInterface::FilespecToFilePath(Files[i]));
			printf("Uploading %s to %s...", (LPSTR)fileAppend(sPackageFolder, Files[i]), (LPSTR)sFilePath);
			CString sResult = UploadFile(theSocket, CMD_UPLOAD, sFilePath, fileAppend(sPackageFolder, Files[i]));
			printf("%s\n", (LPSTR)sResult);
			}
		}

	//	Refresh

	printf("Refreshing Hyperion...");
	return ExecuteArcologyCommand(theSocket, CMD_REFRESH_PACKAGES);
	}
Example #8
0
CString ExecuteUpgrade (CSocket &theSocket, const CString &sCmd)
	{
	int i;

	CString sRoot = fileGetPath(fileGetExecutableFilespec());

	//	Make a list of all executable files to upgrade

	TArray<CString> FileList;
	if (!fileGetFileList(sRoot, NULL_STR, CString("*.exe"), FFL_FLAG_RELATIVE_FILESPEC, &FileList))
		return CString("ERROR: Unable to obtain a list of executable files to upgrade.");

	//	Prepare a request upgrade command

	CStringBuffer Output;
	Output.Write("requestUpgrade (", 16);

	for (i = 0; i < FileList.GetCount(); i++)
		{
		CString sFilespec = fileAppend(sRoot, FileList[i]);

		//	Version

		SFileVersionInfo Info;
		if (!fileGetVersionInfo(sFilespec, &Info))
			{
			printf("ERROR: Unable to get file version: %s\n", (LPSTR)sFilespec);
			continue;
			}

		CIPInteger Version(Info.dwProductVersion);
		CString sVersion = Version.AsString();

		//	Checksum

		DWORD dwChecksum = fileChecksumAdler32(sFilespec);
		if (dwChecksum == 0)
			{
			printf("ERROR: Unable to get file checksum: %s\n", (LPSTR)sFilespec);
			continue;
			}

		CString sOutput = strPattern("{filename:\"%s\" version:%s checksum:%d} ", FileList[i], sVersion, dwChecksum);
		Output.Write(sOutput);
		}

	Output.Write(")", 1);

	//	Send the command

	CString sSend = CString::CreateFromHandoff(Output);
	CString sResult;
	CDatum dResult;
	ExecuteArcologyCommand(theSocket, sSend, &sResult, &dResult);
	if (strEquals(sResult, CString("ERROR")))
		return dResult.AsString();

	//	Show all the files to upgrade

	CDatum dUpgradeDesc = dResult.GetElement(0).GetElement(FIELD_UPGRADE_DESC);
	for (i = 0; i < dUpgradeDesc.GetCount(); i++)
		{
		CDatum dFileDesc = dUpgradeDesc.GetElement(i);

		printf("Upgrading %s\n", (LPSTR)dFileDesc.GetElement(FIELD_FILENAME).AsString());
		}

	//	Confirm

	CString sConfirm = GetInputLine(CString("\nAre you sure you want to upgrade the arcology? [y/n] : "));
	if (*sConfirm.GetParsePointer() != 'y' && *sConfirm.GetParsePointer() != 'Y')
		return NULL_STR;

	//	Upload the new files.

	for (i = 0; i < dUpgradeDesc.GetCount(); i++)
		{
		CDatum dFileDesc = dUpgradeDesc.GetElement(i);
		const CString &sFilename = dFileDesc.GetElement(FIELD_FILENAME);
		CString sFilespec = fileAppend(sRoot, sFilename);

		CString sResult = UploadFile(theSocket, CMD_UPLOAD_UPGRADE, sFilename, sFilespec);
		printf("%s\n", (LPSTR)sResult);
		}

	//	Complete the upgrade

	return ExecuteArcologyCommand(theSocket, CMD_COMPLETE_UPGRADE);
	}